我有一个图像数组,需要将图像的大小调整为35%。这是javascript:
//set up an array of comic images
var imgs = [
'http://static.wixstatic.com/media/057fb3_1e4c8262944649f989b555e3c5e9d242.jpg_1024',
'http://onlinebuilder.myregisteredsite.com/matrix/servlet/ShowAsset;jsessionid=3EE39A2568D60590C3FFD69339141C07?id=102911859',
'http://onlinebuilder.myregisteredsite.com/matrix/servlet/ShowAsset;jsessionid=3EE39A2568D60590C3FFD69339141C07?id=102911864',
'http://onlinebuilder.myregisteredsite.com/matrix/servlet/ShowAsset;jsessionid=3EE39A2568D60590C3FFD69339141C07?id=102911869',
'http://onlinebuilder.myregisteredsite.com/matrix/servlet/ShowAsset;jsessionid=3EE39A2568D60590C3FFD69339141C07?id=102911872',
'http://onlinebuilder.myregisteredsite.com/matrix/servlet/ShowAsset;jsessionid=3EE39A2568D60590C3FFD69339141C07?id=102911877'],
// initialize current to 0
current = 0;
function next() {
current++;
if (current > imgs.length) current = 0;
return imgs[current];
}
function previous() {
current--;
if (current < imgs.length) current = 0;
return imgs[current];
}
// define the first image in terms of a jquery object
var comic = $('<img/>').attr('src', imgs[0]);
// append to DOM
$('#comics').append(comic);
$('#prev').on('click', function () {
comic.attr('src', prev());
});
$('#next').on('click', function () {
comic.attr('src', next());
});
在jquery之上虽然是按钮的简单html代码,但我认为函数prev不起作用是因为我在jquery本身做错了。我已经超过5年没有编程了,而且我很生疏。任何帮助都会很棒。
JSFiddle代码:https://jsfiddle.net/sketchflygirl/4euugfsb/12/ 网站代码用于:monroyart.net
答案 0 :(得分:0)
您已定义previous
功能。
function previous()
但是你是通过prev
comic.attr('src', prev());
答案 1 :(得分:0)
想出来!!!
<style type="text/css">
img{
height:auto;
width:550px;
}
</style>