gpt4 book ai didi

javascript - 如何在 javascript 中添加 img-responsive 类

转载 作者:行者123 更新时间:2023-11-28 08:54:07 24 4
gpt4 key购买 nike

我正在尝试为移动版本制作响应式 slider 。网站是使用 Angular JS 开发的。当我尝试集成 JQuery slider 时,由于 Bootstrap CSS 文件,整个站点都在分发。因此,在那部分我创建了一个普通的 Javascript 代码。以及如何使这些图像具有响应性。下面我添加代码。

    <head>
<script type="text/javascript">
var slideimages = new Array() // create new array to preload images
slideimages[0] = new Image() // create new instance of image object
slideimages[0].src = "images/slide/1.jpg" // set image object src property to an image's src, preloading that image in the process
slideimages[1] = new Image()
slideimages[1].src = "images/slide/2.jpg"
slideimages[2] = new Image()
slideimages[2].src = "images/slide/2.jpg"
</script>
</head>
<body>
<a href="javascript:slidelink()"><img src="firstcar.gif" id="slide" width=100 height=56 /></a>

<script type="text/javascript">

//variable that will increment through the images
var step = 0
var whichimage = 0

function slideit(){
//if browser does not support the image object, exit.
if (!document.images)
return
document.getElementById('slide').src = slideimages[step].src
whichimage = step
if (step<2)
step++
else
step=0
//call function "slideit()" every 2.5 seconds
setTimeout("slideit()",2500)
}

function slidelink(){
if (whichimage == 0)
window.location = "#"
else if (whichimage == 1)
window.location = "#"
else if (whichimage == 2)
window.location = "#"
}

slideit()

</script>

最佳答案

以前的答案是正确的,但您必须对 jQuery 使用 $:

$(slideimages[0]).addClass("img-responsive");

没有 jQuery:

slideimages[0].className += "img-responsive";

关于javascript - 如何在 javascript 中添加 img-responsive 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27202749/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com