|
|
|
ช่วยหน่อยค่าาาา --- > JavaScript ..jQuery slider เซตเวลาในการเลื่อนแต่ละหน้าค่ะ |
|
|
|
|
|
|
|
Code
var presentationCycle = {
/*
* Presentation Cycle - a jQuery Cycle extension
* Author: Gaya Kessler
* URL: http://www.gayadesign.com
* Date: 03-11-09
*/
//slide options
slideTimeout: 6000,
containerId: "presentation_container",
//cycle options
cycleFx: 'scrollHorz',
cycleSpeed: 600,
//variables this script need
itemCount: 0,
currentItem: 0,
itemBarWidth: 0,
barContainer: "",
barContainerActive: "",
barContainerOverflow: "",
disableAnimation: false,
init: function() {
presentationCycle.itemCount = $('#' + presentationCycle.containerId).children().length;
presentationCycle.barContainer = $("<div></div>");
$(presentationCycle.barContainer).addClass("pc_bar_container");
var subtrackSpace = (presentationCycle.itemCount * presentationCycle.barHeight);
var totalWidth = $('#' + presentationCycle.containerId).innerWidth() - presentationCycle.barDisplacement;
var fillWidth = Math.floor((totalWidth - subtrackSpace) / (presentationCycle.itemCount - 1));
presentationCycle.itemBarWidth = fillWidth;
for (var i = 0; i < presentationCycle.itemCount; i++) {
var item = $("<div> </div>").appendTo(presentationCycle.barContainer);
var extra_bar = true;
if (i == 0) {
$(item).addClass("left");
$(item).css({
backgroundImage: "url(" + presentationCycle.barImgLeft + ")",
height: presentationCycle.barHeight + "px",
width: presentationCycle.barHeight + "px"
});
} else if (i == (presentationCycle.itemCount - 1)) {
$(item).addClass("right");
$(item).css({
backgroundImage: "url(" + presentationCycle.barImgRight + ")",
height: presentationCycle.barHeight + "px",
width: presentationCycle.barHeight + "px"
});
extra_bar = false;
} else {
$(item).addClass("center");
$(item).css({
backgroundImage: "url(" + presentationCycle.barImgCenter + ")",
height: presentationCycle.barHeight + "px",
width: presentationCycle.barHeight + "px"
});
}
$(item).attr('itemNr', (i + 1));
$(item).css('cursor', 'pointer');
$(item).click(function() {
presentationCycle.gotoSlide($(this).attr('itemNr'));
});
if (extra_bar == true) {
var item = $("<div> </div>").appendTo(presentationCycle.barContainer);
$(item).addClass("bar");
$(item).css({
backgroundImage: "url(" + presentationCycle.barImgBarEmpty + ")",
height: presentationCycle.barHeight + "px",
width: fillWidth + "px"
});
}
}
var overflow = $("<div></div>");
$(overflow).addClass("pc_bar_container_overflow");
$(overflow).css({
overflow: "hidden",
width: totalWidth + "px"
});
var underflow = $("<div></div>");
$(underflow).addClass("pc_bar_container_underflow").appendTo(overflow);
presentationCycle.barContainerActive = $(presentationCycle.barContainer).clone().appendTo(underflow);
$(presentationCycle.barContainerActive).removeClass("pc_bar_container");
$(presentationCycle.barContainerActive).children().each(function () {
$(this).css({
backgroundPosition: "right"
});
if ($(this).css("background-image").match(presentationCycle.barImgBarEmpty)) {
var newImg = $(this).css("background-image").replace(presentationCycle.barImgBarEmpty, presentationCycle.barImgBarFull);
$(this).css("background-image", newImg);
}
});
$(overflow).css({
width: presentationCycle.barHeight + "px",
height: presentationCycle.barHeight + "px"
});
presentationCycle.barContainerOverflow = overflow;
$('#' + presentationCycle.containerId).cycle({
fx: presentationCycle.cycleFx,
speed: presentationCycle.cycleSpeed,
timeout: presentationCycle.slideTimeout,
before: function(currSlideElement, nextSlideElement) { presentationCycle.beforeSlide(currSlideElement, nextSlideElement); }
});
presentationCycle.barContainer.appendTo($('#' + presentationCycle.containerId));
overflow.appendTo($('#' + presentationCycle.containerId));
var i = 0;
$(".pc_bar_container_overflow .left, .pc_bar_container_overflow .center, .pc_bar_container_overflow .right").each(function () {
$(this).attr('itemNr', (i + 1));
$(this).css('cursor', 'pointer');
$(this).click(function() {
presentationCycle.gotoSlide($(this).attr('itemNr'));
});
i++;
});
},
beforeSlide: function(currSlideElement, nextSlideElement) {
if (presentationCycle.currentItem == 0) {
presentationCycle.currentItem = 1;
} else {
presentationCycle.currentItem = (presentationCycle.itemCount - ($(nextSlideElement).nextAll().length)) + 2;
}
presentationCycle.animateProcess();
},
animateProcess: function() {
var startWidth = (presentationCycle.itemBarWidth * (presentationCycle.currentItem - 1)) + (presentationCycle.barHeight * presentationCycle.currentItem);
if (presentationCycle.currentItem != presentationCycle.itemCount) {
var newWidth = (presentationCycle.itemBarWidth * (presentationCycle.currentItem)) + (presentationCycle.barHeight * (presentationCycle.currentItem + 1));
} else {
var newWidth = presentationCycle.barHeight;
}
$(presentationCycle.barContainerOverflow).css({
width: startWidth + "px"
});
if (presentationCycle.disableAnimation == false) {
$(presentationCycle.barContainerOverflow).stop().animate({
width: newWidth + "px"
}, (presentationCycle.slideTimeout - 100));
}
},
gotoSlide: function(itemNr) {
$(presentationCycle.barContainerOverflow).stop();
presentationCycle.disableAnimation = true;
$('#' + presentationCycle.containerId).cycle((itemNr - 1));
$('#' + presentationCycle.containerId).cycle('pause');
}
}
นี่เป็นโค้ดค่ะ แต่ล้ะเพจมันเลื่อน 6 วิ ถ้าอยากให้มันนับคำในเพจ และความเร็วในการเลื่อนขึ้นอยู่กับจำนวนคำในเพจ
หนูควรทำยังไงคะ
Tag : PHP, jQuery
|
ประวัติการแก้ไข 2013-01-03 16:47:53
|
|
|
|
|
Date :
2013-01-03 16:46:29 |
By :
myGypz |
View :
810 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ค่า page มาจากไหนครับ
|
|
|
|
|
Date :
2013-01-03 20:30:49 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มันมีอยู่สองหน้าค่ะ คือโค้ดด้านบนเป็น js และโค้ดด้านล่างนี้เป็น html
หนูอยากให้แต่ละเพจความเร็วในการเลื่อนไม่เท่ากัน ถ้ามีคำเยอะๆให้เลื่อนช้า คำน้อยๆให้เลื่อนเร็ว
รบกวนด้วยค่ะพี่วิน :)
Code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl" lang="nl">
<head>
<title>Gaya Design - Presentation Cycle</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="Pragma" content="no-cache" />
<!-- Stylesheets -->
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="css/presentationCycle.css" />
<!-- Scripts -->
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js?ver=1.3.2'></script>
<script type='text/javascript' src='js/jquery.cycle.all.min.js'></script>
<script type='text/javascript' src='js/presentationCycle.js'></script>
</head>
<body>
<div class="container">
<h1>Presentation Cycle Example</h1>
<div id="presentation_container" class="pc_container">
<div class="pc_item">
<div class="desc">
<h1>Server Park</h1>
Consectetur adipiscing elit. Nunc quis tellus eros.
Nam blandit diam id turpis bibendum nec rutrum dui pulvinar. Quisque fermentum,
dolor ut adipiscing suscipit, leo lorem malesuada mauris, vitae dapibus mi
ligula ut nunc.
</div>
<img src="images/slide1.jpg" alt="slide1" />
</div>
<div class="pc_item">
<div class="desc">
<h1>iPhone Apps</h1>
Consectetur adipiscing elit. Nunc quis tellus eros.
Nam blandit diam id turpis bibendum nec rutrum dui pulvinar. Quisque fermentum,
dolor ut adipiscing suscipit, leo lorem malesuada mauris, vitae dapibus mi
ligula ut nunc.
</div>
<img src="images/slide2.jpg" alt="slide2" />
</div>
<div class="pc_item">
<div class="desc" style="left: 0px;">
<h1>Wordpress Extensions</h1>
Consectetur adipiscing elit. Nunc quis tellus eros.
Nam blandit diam id turpis bibendum nec rutrum dui pulvinar. Quisque fermentum,
dolor ut adipiscing suscipit, leo lorem malesuada mauris, vitae dapibus mi
ligula ut nunc.
</div>
<img src="images/slide3.jpg" alt="slide3" />
</div>
<div class="pc_item">
<div class="desc" style="left: 165px;">
<h1>City Skyline</h1>
Consectetur adipiscing elit. Nunc quis tellus eros.
Nam blandit diam id turpis bibendum nec rutrum dui pulvinar. Quisque fermentum,
dolor ut adipiscing suscipit, leo lorem malesuada mauris, vitae dapibus mi
ligula ut nunc.
</div>
<img src="images/slide4.jpg" alt="slide4" />
</div>
<div class="pc_item">
<div class="desc">
<h1>Mario Finds Peach</h1>
Consectetur adipiscing elit. Nunc quis tellus eros.
Nam blandit diam id turpis bibendum nec rutrum dui pulvinar. Quisque fermentum,
dolor ut adipiscing suscipit, leo lorem malesuada mauris, vitae dapibus mi
ligula ut nunc.
</div>
<img src="images/slide5.jpg" alt="slide5" />
</div>
<div class="pc_item">
<div class="desc">
<h1>Said and Done</h1>
Consectetur adipiscing elit. Nunc quis tellus eros.
Nam blandit diam id turpis bibendum nec rutrum dui pulvinar. Quisque fermentum,
dolor ut adipiscing suscipit, leo lorem malesuada mauris, vitae dapibus mi
ligula ut nunc.
</div>
<img src="images/slide6.jpg" alt="slide6" />
</div>
</div>
<script type="text/javascript">
presentationCycle.init();
</script>
</div>
</body>
</html>
|
ประวัติการแก้ไข 2013-01-04 09:02:29
|
|
|
|
Date :
2013-01-04 09:01:14 |
By :
myGypz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|