[英]Move a div with mouse pointer
I'm trying to do exactly as it is in this link. 我正在尝试完全按照此链接中的说明进行操作。 (The stripe on the banners with the read more link) https://toyota.jp/vitz (带有阅读更多链接的横幅上的条纹) https://toyota.jp/vitz
What I tried so far doesn't work as expected. 到目前为止,我尝试的操作无法按预期进行。 It moves the whole stripe apart from the range. 它将整个条带移动到范围之外。
$(document).on("click mousemove", ".spec-slider-wrap", function(e) { var x = e.clientX; var y = e.clientY; var newposX = x - 700; var newposY = y - 350; $(".stripe").css("transform", "translate3d(" + newposX + "px," + newposY + "px,0px)"); });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div> <span class="word">More</span> <span class="arrow-wrap"> <span class="arrow-pulse-right"></span> </span> </div>
here the working code. 这里是工作代码。 https://jsbin.com/geyudivuru/edit?html,css,js,output https://jsbin.com/geyudivuru/edit?html,css,js,输出
<div class="parent" style="">
<div class="stripe">
<span class="word">More</span>
<span class="arrow-wrap">
<span class="arrow-pulse-right"></span>
</span>
<div>
</div>
.stripe {
width: 100%;
background: red;
position: absolute;
height: 40px;
display: none;
}
.parent {
position: relative;
height: 400px;
background: #ddd;
}
$ = jQuery;
$(document).on("mousemove", function(e) {
var x = e.clientX;
var y = e.clientY;
var newposX = x - 700;
var newposY = y;
$('.stripe').css({top: newposY, display: 'block'})
});
$('.parent').mouseleave(function(){
$('.stripe').css({top: 0, display: 'none'})
})
add styling to divs and you'll get what you need. 将样式添加到div,您将获得所需的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.