我使用的是HTML5和JavaScript,如何让用户在进入网站后立即更改图片宽度?
答案 0 :(得分:0)
我很久以前在我的文件夹中的某处。我添加了一些评论以了解正在做什么并且我更改了图像。
但基本上,它是一种简单的方法(没有jQuery)。
<!-- This is where you image can go -->
<p>
<img id="myImage"
src="https://static.boredpanda.com/blog/wp-content/uploads/2016/08/cute-kittens-69-57b32c431e8a7__605.jpg" alt=""
width="303"
height="237" />
</p>
<!-- The buttons to control -->
<button onclick ="increaseSize()">Bigger</button>
<button onclick ="decreaseSize()">Smaller</button>
<!-- The script that scales the image -->
<script>
// Our image.
var image = document.getElementById("myImage");
// The value we will add/substract to the image's dimension.
var scale = 50;
function increaseSize() {
image.width += scale;
image.height += scale;
};
function decreaseSize() {
image.width -= scale;
image.height -= scale;
};
</script>
&#13;
顺便说一句,你不应该在这个网站上要求代码。你必须在你身边工作,想出你已经取得的成就以及你所处的位置。 :)
答案 1 :(得分:-1)
https://humansky.com/2011/12/accidentally-adding-a-git-submodule/可能重复。
您可能必须使用类似HTML5画布的内容来获得此目的。使用画布,您可以非常轻松地将图像作为元素进行操作。