Vue.js 和 jQuery 都是前端开发中常用的 JavaScript 库,但它们有着不同的特点和用途。
总的来说,Vue.js 更适合大型复杂的单页应用程序开发,而 jQuery 则更适合简单的交互效果和常规的 DOM 操作。
案例代码:
HTML 代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>图片放大镜效果</title>
<style>
.wrapper {
width: 600px;
margin: 0 auto;
position: relative;
}
.small {
width: 200px;
height: 200px;
overflow: hidden;
margin: 50px 0;
border: 2px solid #ccc;
float: left;
}
.small img {
width: 100%;
}
.big {
width: 300px;
height: 300px;
position: absolute;
top: 0;
left: 100%;
margin-left: 20px;
border: 2px solid #ccc;
display: none;
}
.big img {
width: 100%;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="small">
<img src="small.jpg" alt="图片">
<div class="mark"></div>
</div>
<div class="big">
<img src="big.jpg" alt="图片">
</div>
</div>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>
$(function() {
var mark = $('.mark'),
small = $('.small'),
big = $('.big'),
bigImg = $('.big img'),
smallImg = $('.small img');
// 鼠标移入 small 区域,显示 mark 和 big
small.on('mouseenter', function() {
mark.show();
big.show();
});
// 鼠标移出 small 区域,隐藏 mark 和 big
small.on('mouseleave', function() {
mark.hide();
big.hide();
});
// 鼠标移动,改变 mark 和 big 的位置和内容
small.on('mousemove', function(ev) {
var left = ev.pageX - small.offset().left - mark.width() / 2,
top = ev.pageY - small.offset().top - mark.height() / 2;
if (left < 0) {
left = 0;
} else if (left > small.width() - mark.width()) {
left = small.width() - mark.width();
}
if (top < 0) {
top = 0;
} else if (top > small.height() - mark.height()) {
top = small.height() - mark.height();
}
mark.css({
left: left + 'px',
top: top + 'px'
});
bigImg.css({
left: -left * bigImg.width() / small.width() + 'px',
top: -top * bigImg.height() / small.height() + 'px'
});
});
});
</script>
</body>
</html>
原文地址:https://blog.csdn.net/cgithxk/article/details/129635388
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_28586.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!