jquery - How to resize an image while dragging a cursor using jQuery (Draggable & Resizable)
问题描述
I want to recreate the draggable event of the image in this site https://alpine-groupemichel.com/alpine-a110 .
I managed to drag the cursor but i don't know how to resize the image following the offset().left of the cursor.
<section id="wide-description" class="third">
<div class="container-fluid">
<div class="row">
<div class="-wide-image relative">
<div class="slide-img relative">
<img src="https://alpine-groupemichel.com/sites/default/files/c7de023e669081e77b86f9854f99672101ecfe5f.jpeg" alt="NOUVELLE ALPINE A110" class="img-responsive">
<div class="sliding-image">
<img src="https://alpine-groupemichel.com/sites/default/files/8ee728e0ec67b7adf195fb8b26dd20373c6869cf.jpeg" alt="NOUVELLE ALPINE A110">
</div>
<span id="drag-cursor">
<span id="slider-cursor"></span>
</span>
</div>
<div class="modelRevealInfos">
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-6 no-padding">
1103kg<br>
252 ch<br> 4,5 s 0-100km/h<br> </div>
<div class="col-md-6 col-sm-6 col-xs-6 no-padding">
4 180 mm<br> 1 798 mm<br> 1 252 mm<br>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
$(document).ready(function(){
var cursor = $('#drag-cursor');
var img = $('.sliding-img');
var xPos=0;
cursor.draggable({
axis: 'x',
containment: $('.relative'),
drag: function(xPos) {
var offset = $(this).offset();
var xPos = offset.left;
console.log(xPos);
}
});
});
解决方案
我找到了解决方案:
$(document).ready(function(){
$('.sliding-image img').css("width",$(window).width());
$(window).resize(function() {
$('.sliding-image img').css("width",$(window).width());
});
if( $('#drag-cursor').length ){
$( "#drag-cursor" ).draggable({
axis: "x",
containment: $('-wide-img'),
drag : function( event, ui ) {
var offset = $(this).offset();
var xPos = offset.left;
$('.sliding-image').css("width",xPos);
}
});
};
});
推荐阅读
- c# - 无法使用 OpenCover for Selenium webdriver 获得代码覆盖率
- android - 沿着画布的整个高度绘制垂直线?
- windows - 文件夹 - 文件监控警报
- javascript - 如何通过 javascript 访问和打印 CSS3 @keyframes 比例和其中的相应样式?
- android - 在 dart/flutter 项目中包含 C 文件
- npp - 如何确定帧的源图像行步长?
- firebase - Firebase 更新 apple-app-site-association
- android - Android AWS S3 库 - 同步上传
- sql - 动态Sql在子选择中使用变量
- count - SPARQL 中的 GROUP 和 COUNT