当我向上或向下拖动图像时,如何更改图像的大小
How can I change the size of an image when I drag the image up or down?
大家好,我是编程初学者。当我在网页上上上下拖动图像时,我想更改图像的大小
向上拖动时大小应该减小,向下拖动时大小应增大。我可以通过动画改变它的大小,现在我希望它在我拖动它时发生。这是代码
<!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>
这不是一个现成的例子,但它的想法会对您有所帮助。。
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
});
Demo
为了在你的网站上实现这一点,而不是使用event.pageY
,你可能需要对图像的height
和position
进行一些计算,并尝试计算出你需要在图像中添加或删除多少像素。
相关文章:
- Javascript将图像src更改为淡入淡出
- 如何使图像自动更改
- 鼠标悬停时AngularJS图像源更改
- 如何检测移动浏览器(PHP/Javascript),然后进行图像/文本更改
- jquery ui按钮图像没有更改
- 图像宽度:更改父块高度后的自动和最大高度
- Nivo 滑块 URL 不会随图像而更改
- 使用单击图像映射更改设置为背景的精灵图像的位置
- 如何在单击 SVG 用作背景图像时更改其填充颜色
- 使用 jQuery 预览图像,更改悬停图像大小
- 点击图像部分 图像应该更改
- 选择“更改”时,“背景图像”会更改
- 更改图像属性更改时的不透明度
- CSS / JavaScript过渡:如果图像快速更改,我的CSS过渡不适用于图库
- 单击图像时背景图像会更改
- 将背景图像序列更改为spritesheet
- 如何使用JavaScript在每次点击图像时更改图像标签的URL
- JavaScript中有没有一种方法可以在解析HTML时在浏览器加载图像之前更改图像路径
- 单击图像时更改段落文本(Javascript)
- 在PopupPanel中添加图像和更改文本字体大小无效