大家好,我是编程的初学者。当我在网页上上下拖动图像时,我想更改图像的大小吗?
当我向上拖动它时,大小应该会减小,当我向下拖动它时,大小应该会增加。我现在可以通过动画改变它的大小,我希望它发生在我拖动它的时候。下面是代码
<!DOCTYPE html>
<html>
<head>
<style>
div.hidden
{
width:20px;
height:80px;
background:white;
position:relative;
overflow:hidden;
left:50px;
top:400px;
-webkit-animation-timing-function:linear;
-webkit-animation:myfirst 5s ;
}
@-webkit-keyframes myfirst /* Safari and Chrome */
{
from {background:white; height:0px;width:0;left:50px; top:40px; }
to {background:white; height:80px;width:20px;left:50px; top:430px;}
}
</style>
</head>
<body background="road.jpg">
<div style="position:relative;width:126px;height:350px; overflow:hidden; border: solid 1px;left:639px;top:307px;">
<div class="hidden";></div>
</div>
To: <input type="text" name ="To"><br><br>
</body>
</html>
发布于 2013-07-20 09:46:48
这不是一个现成的示例,但它的想法将对您有所帮助。
var dragging = false;
$('img').mousedown(function(){
dragging = true; // Detect if we are dragging the image
});
$(document).mousemove(function(){
if(dragging === true) {
$('img').height(event.pageY + 'px'); // Detect how many pixels high from the top of the screen
}
});
$(document).mouseup(function(){
dragging = false; // detect when we are done
});
为了让它在你的站点或其他地方工作,而不是使用event.pageY
,你可能不得不对图像的height
,图像的position
进行一些计算,并尝试计算出你需要在图像中添加或删除多少像素。
https://stackoverflow.com/questions/17760835
复制相似问题