鼠标的滑轮向下移动,广告不移动的小案例

鼠标的滑轮向下移动,广告不移动的小案例

这个案例需要用到jquery

jquery-3.3.1.js

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="js/jquery-3.3.1.js"></script>
<style>
   body{
       display:flex;
       margin: 0;
   }
   .box{
       cursor: pointer;
       width: 100px;
       height: 100px;
       background: green;
       border: 1px solid #aaa;
       border-radius: 8px;
       text-align: center;
       line-height: 100px;
       color: #fff;
       font-size: 24px;
       position: absolute;
       left: 600px;
       top: 200px;
   }
</style>
</head>
<body style="height: 3000px;">
<div class="box animate swing">我是广告</div>
<script>
    $(function(){
        var t = $('.box').offset().top;
        $(document).scroll(function(){
            var l = $(document).scrollTop();
            $(".box").css('top',t+l);
        })
    })
</script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现导入图片鼠标滑轮放缩和左键按住移动,可以使用QGraphicsView和QGraphicsScene来实现,具体步骤如下: 1. 创建一个QGraphicsView对象和QGraphicsScene对象,并将QGraphicsScene设置为QGraphicsView的场景。 2. 使用QGraphicsPixmapItem将图片添加到QGraphicsScene中。 3. 重写QGraphicsView的wheelEvent()方法,实现鼠标滑轮放缩图片的功能。 4. 重写QGraphicsView的mousePressEvent()、mouseMoveEvent()和mouseReleaseEvent()方法,实现鼠标左键按住移动图片的功能。 下面是一个简单的代码示例: ```python from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QGraphicsPixmapItem from PyQt5.QtGui import QPixmap from PyQt5.QtCore import Qt class ImageViewer(QGraphicsView): def __init__(self, parent=None): super().__init__(parent) # 创建QGraphicsScene对象 self.scene = QGraphicsScene(self) self.setScene(self.scene) # 添加图片 self.image = QGraphicsPixmapItem() self.scene.addItem(self.image) # 设置滚动条策略 self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setRenderHint(QPainter.Antialiasing, True) # 设置鼠标追踪 self.setMouseTracking(True) # 设置缩放比例 self.scaleFactor = 1.0 def loadImage(self, filename): # 加载图片 pixmap = QPixmap(filename) self.image.setPixmap(pixmap) self.setSceneRect(pixmap.rect()) def wheelEvent(self, event): # 放缩图片 if event.angleDelta().y() > 0: self.scaleFactor *= 1.1 else: self.scaleFactor /= 1.1 self.scale(self.scaleFactor, self.scaleFactor) def mousePressEvent(self, event): # 记录鼠标按下的位置 if event.button() == Qt.LeftButton: self.lastPos = event.pos() def mouseMoveEvent(self, event): # 移动图片 if event.buttons() & Qt.LeftButton: delta = event.pos() - self.lastPos self.lastPos = event.pos() self.translate(delta.x(), delta.y()) def mouseReleaseEvent(self, event): pass ``` 在上面的代码中,loadImage()方法用于加载图片,wheelEvent()方法用于放缩图片,mousePressEvent()、mouseMoveEvent()和mouseReleaseEvent()方法用于移动图片。注意,在mousePressEvent()方法中要记录鼠标按下的位置,在mouseMoveEvent()方法中要计算鼠标移动的距离,并将场景平移相应的距离。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值