让我看看你的问题是否正确,
如果您正在寻找一种在单击 div 或其他内容时更改背景图像(由超大尺寸使用)的方法,那么有很多方法可以做到这一点。
以下代码可能会帮助您,它将在其末尾用“-bw”替换活动幻灯片图像名称。
例如:单击类名为“click-me”的 div 会将背景图像从“image.jpg”更改为“image-bw.jpg”
function changeBg() {
var $supersizedImg = $("#supersized .activeslide img"),
imgSrc = $supersizedImg.attr('src');
imgSrcArray = imgSrc.split('/'); //split the image source by '/'
fullFileName = imgSrcArray[imgSrcArray.length - 1]; //get the file name
fileName = fullFileName.split('.'); //split that file name by '.'
fileName[0] = fileName[0] + '-bw'; //grab the first array element(which is filename without extension and add a '-bw' in the end)
fileName = fileName.join('.'); //join the new file name with its extension with a '.'
imgSrcArray[imgSrcArray.length - 1] = fileName; //add the new file name the the last element of imgSrcArray.
imgSrcArray = imgSrcArray.join('/'); //join the whole url by '/'
$supersizedImg.attr('src', imgSrcArray); //add the new url to the img src of supersized
}
$('.click-me').on('click', changeBg); //call changeBg function when a div is clicked
希望能帮助到你。