我正在嘗試使用jQuery循環來旋轉頁面上的一些圖像。圖像寬度爲1400px,這意味着對於屏幕分辨率較小的用戶來說,圖像的右側會消失。JavaScript - 根據瀏覽器窗口的大小移動圖像
我想讓圖像在圖像的任意一邊都有相同的數量,因此圖像的中心位於觀察窗口的中心。
如果你看看http://renegadeox.com/並調整瀏覽器窗口大小,你會明白我的意思。
如何使用javascript將圖像相對於容器左移並保持圖像居中?
下面是完整的代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="http://malsup.github.com/jquery.cycle.all.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
$('.slideshowWrap').cycle({
fx: 'fade', // http://malsup.com/jquery/cycle/ Background rotater
});
});
</script>
<div style="margin: 0 auto" class="slideshowWrap">
<div class="homeslideshow">
<img src="background_01.jpg" alt="" />
</div>
<div class="homeslideshow">
<img src="background_02.jpg" alt="" />
</div>
<div class="homeslideshow">
<img src="background_03.jpg" alt="" />
</div>
</div>
</body>
</html>
嘿javiercf - 感謝輸入。我已經放棄了它,但我無法完成它的工作。我並不是很瞭解JavaScript,但我明白這裏會發生什麼,但不幸的是,第一張圖片淡出,然後沒有任何內容。加上第一張圖片並沒有居中在頁面中間的第一位:( –
我剛剛編輯了代碼,你在哪裏,沒有工作,新的代碼搞錯了! – javiercf
你是個怪人天才男人!嗚呼!!它的工作!非常感謝你。:) –