http://developer.yahoo.net/yui/slider/index.html
ï¼æ¬æä¸ã§ã¯ãã¹ã©ã¤ãã¼ã®ã¤ã¾ã¿ãã¹ã©ã¤ãã¼ã»ãµã ãã¤ã«ã¨è¨³ãã¦ãã¾ããã¹ã©ã¤ãã¼ã¨æ¸ããå ´åãèæ¯é¨åãããã¯å ¨ä½ãæãã®ã§æ³¨æãã¦ãã ããã
Yahoo! UI Library: Slider
The Slider component is a UI control that enables the user to adjust values in a finite range along one or two axes. Typically, the Slider Control is used in a web application as a rich, visual replacement for an input box that takes a number as input. The Slider component can also easily accommodate a second dimension, providing x,y output for a selection point chosen from a rectangular region.
This page describes the Slider component and provides examples of its use. It contains these sections:
Sliderã³ã³ãã¼ãã³ãã使ãã¨ãã¹ã©ã¤ãã¼ã使ã£ã¦å¤è¨å®ãå¯è½ã«ãªãã¾ããã¹ã©ã¤ãã¼ã®å¤åã¯æéã§ã1ã¤ã®è»¸ã¾ãã¯ï¼ã¤ã®è»¸ãè¨ãããã¾ããã¹ã©ã¤ãã¼ã³ã³ããã¼ã©ã¯ãæ°å¤å ¥åããã¯ã¹ã®ä»£ããã«ããªããã§è¦è¦çãªWEBã¢ããªã±ã¼ã·ã§ã³ã¨ãã¦ä½¿ããããã¨ãå¤ãã§ããSliderã³ã³ãã¼ãã³ãã¯ãX,Y次å ã«ãç°¡åã«é©ç¨ã§ãã¾ãããããã¤ããã°ãé·æ¹å½¢ã®é åãããã¤ã³ããé¸æãããã¨ãå¯è½ã§ãã
以ä¸ãã³ã³ãã¼ãã³ãã®ãµã³ãã«ã¨ä½¿ãæ¹ãè¼ãã¦ããã¾ãã
Getting Started
ã³ã³ãã¼ãã³ãéã®ä¾åé¢ä¿ã«æ³¨æãã¦ãã ããã
<!-- Namespace source file --> <script src = "http://yourwebsite.com/util/YAHOO.js" ></script> <!-- Dependency source files --> <script src = "http://yourwebsite.com/util/dom.js" ></script> <script src = "http://yourwebsite.com/util/event.js" ></script> <script src = "http://yourwebsite.com/util/dragdrop.js" ></script> <!-- Slider source file --> <script src = "http://yourwebsite.com/widget/slider.js" ></script>Sliderã³ã³ãã¼ãã³ã㯠YAHOO.widget.Slider. ã§å®ç¾©ããã¾ã
To create a slider you will need ID references to two page elements: one for the slider background and one for the thumb. The thumb should be a child of the background element.
<div id="sliderbg"> <div id="sliderthumb"><img src="sliderthumbimg" /></div> </div>The elements can be styled as desired, but both elements should be positioned. Since the background area is clickable, the size of the elements matter. In typical implementations you will need to make the background width(for horizontal sliders) or height(for vertical sliders) the total number of pixels you want the slider to be able to move plus the width or height of the thumb element:
Here is a Slider layout example (Note: not to scale, and the dimensions are just an example, not a recommendation):
HTMLã¨CSSã®æºåã®åºæ¬
ã¹ã©ã¤ãã¼ãä½ãã«ã¯ãï¼ã¤ã®è¦ç´ ã¸ã®IDãªãã¡ã¬ã³ã¹ãå¿ è¦ã¨ãã¾ãã
ï¼ã¤ç®ã¯ã¹ã©ã¤ãã¼ã®èæ¯ã¨ãªãè¦ç´ ãï¼ã¤ç®ã¯ãµã ãã¤ã«ã§ãããµã ãã¤ã«ã¯èæ¯è¦ç´ ã®åä¾ï¼child node?)ã§ãªããã°ããã¾ããã<div id="sliderbg"> <div id="sliderthumb"><img src="sliderthumbimg" /></div> </div>ï¼ã¤ã®è¦ç´ ãåæã«å¸æã©ããã®é ç½®ã«ãªã£ã¦ãããããããã¾ãããããã£ããã¨ä½ç½®ã¥ãã¦ãããæ¹ãããã§ããããèæ¯ã®é åã¯ã¯ãªãã¯å¯è½ãªã®ã§ãè¦ç´ ã®ãµã¤ãºãéè¦ã«ãªã£ã¦ãã¾ãã水平軸ã®ã¹ã©ã¤ãã¼ãä½ãå ´åã¯èæ¯ã®widthãããããã¯åç´è»¸ã®ã¹ã©ã¤ãã¼ãä½ãå ´åã¯heightã®å¤ããå ¨ä½ã®å¹ ï¼ã¹ã©ã¤ããããå¹ ï¼ï¼ãµã ãã¤ã«åã®å¤ã追å ããå¤ãã«ããã®ãä¸è¬çãªããæ¹ã§ãã
èæ¯ã®width(or height) = ã¹ã©ã¤ãããå¹ ã+ ãµã ãã¤ã«åã®å¹
ï¼ä¸è¨ã®çµµãåèã«ããã¨åãããããã§ãã¹ã©ã¤ãã¼ã®ã¬ã¤ã¢ã¦ããµã³ãã«ã§ããï¼æ³¨æï¼ãµã³ãã«ç¨ã®ç»åã§ãã縮尺ããã£ã¦ã¾ãããããã®ãããªã¹ã©ã¤ãã¼ãå§ããããã§ã¯ããã¾ããï¼
Initializing the Slider
The following example creates a horizontal slider object.
var slider; function sliderInit() { slider = YAHOO.widget.Slider.getHorizSlider("sliderbg", "sliderthumb", 0, 200); }The getHorizSlider method produces a horizontal slider. The getVertSlider method produces a vertical slider. The full constructor for both looks like this:
YAHOO.widget.Slider.getHorizSlider(string bgid, string thumbid, int leftup, int rightdown, [int tick])Where:
- bgid is the id of the slider background
- thumbid is the id of the slider thumb
- leftup is the number of pixels the slider can move left or up (depending on orientation)
- rightdown the number of pixels the slider can move right or down (depending on orientation)
- tick is the optional tick interval (see Setting up Tick Marks for more information)
The Slider component in the example above is created so that it can be moved 200 pixels to the right, and 0 pixels to the left. It is also possible to configure the slider thumb to start in the center of the background, which would make sense if your default landing zone or zero value is in the middle of the range.
See the additional topics below in Using Slider or under Examples for functional examples.
ã¹ã©ã¤ãã¼ã®åæå
æ°´å¹³ãªã¹ã©ã¤ãã¼ã»ãªãã¸ã§ã¯ããä½ããµã³ãã«ã§ãã
var slider; function sliderInit() { slider = YAHOO.widget.Slider.getHorizSlider("sliderbg", "sliderthumb", 0, 200); }getHorizSlider()ã¡ã½ããã¯æ°´å¹³ãªã¹ã©ã¤ãã¼ãä½ãã¾ãã
getVertSlider()ã¡ã½ããã¯åç´ãªã¹ã©ã¤ãã¼ãä½ãã¾ãã両è ã¨ãã³ã³ã¹ãã©ã¯ã¿ã¯ä»¥ä¸ã®ããã«ãªãã¾ããYAHOO.widget.Slider.getHorizSlider(string bgid, string thumbid, int leftup, int rightdown, [int tick])
- bgidãã¯ã¹ã©ã¤ãã¼ã®èæ¯ã®IDã§ã
- thumbidãã¯ãã¹ã©ã¤ãã¼ãµã ãã¤ã«ï¼ãã¿ã³ï¼åã£æï¼ï¼ã®IDã§ã
- leftupã¯å·¦æ¹åããããã¯ä¸æ¹åã«åããããã¯ã»ã«å¹ ã§ã
- righdown ã¯å³æ¹åããããã¯ä¸æ¹åã«åããããã¯ã»ã«å¹ ã§ã
- tickã¯ããã¯ã®ééã§ãï¼ããä¸å®ã®ééãããã¦ã¹ã©ã¤ããããã¨ã詳ãããã¨ã¯å¾è¿°ï¼
ãµã³ãã«ã®Sliderã³ã³ãã¼ãã³ãã¯å³æ¹åã«200pxãå·¦æ¹åã«0pxåããã¾ããã¹ã©ã¤ãã¼ã»ãµã ãã¤ã«ãèæ¯ã®ä¸å¿ã«è¨å®ãããã¨ãå¯è½ã§ãããã®å ´åã¼ãç¹ãå¤åã®çãä¸ã«ãããããªå ´åã«æå³ããªãã¾ãã
è£è¶³ã¯ãµã³ãã«ãè¦ã¦ãã ããã
Using Slider
This section describes customizations to the Slider.
- Setting Up Tick Marks
- Creating Slider Animation
- Customizing Events
ã¹ã©ã¤ãã¼ã使ããã®ã»ã¯ã·ã§ã³ã§ã¯ã¹ã©ã¤ãã¼ã®ã«ã¹ã¿ãã¤ãºæ¹ãè¼ãã¦ãã¾ã
- ããã¯ã®è¨å®
- ã¹ã©ã¤ãã¼ã®ã¢ãã¡ã¼ã·ã§ã³ãã¤ãã
- ã¤ãã³ãã®ã«ã¹ã¿ãã¤ãº
以ä¸ä¸ã¤ã®é ç®ã®èª¬æãæ¸ãã¦ããã¾ãã
1.Setting Up Tick Marks
Sometimes you may want your slider to move in fixed pixel increments instead of pixel by pixel. The slider component supports this with an optional fifth parameter to the getHorizSlider and getVertSlider methods for the tick interval. The following will produce a vertical slider with tick positions every 20 pixels:
var slider; function sliderInit() { slider = YAHOO.widget.Slider.getVertSlider("sliderbg", "sliderthumb", 0, 200, 20); }When the background is clicked, or the thumb dragged, the slider automatically snaps to the nearest tick position.
1.ããã¯ã®è¨å®
ä¸ãã¯ã»ã«ãã¤åããã®ã§ã¯ãªãã移åå¹ ãåºå®ãã¦é£ã°ãé£ã°ãã«ã¹ã©ã¤ãã¼ãåããããæãããããããã¾ãããsliderã³ã³ãã¼ãã³ãã¯ãgetHorizSlider()ã¨getVertSlider()ã«ããã¯ãã»ããã§ãããããäºã¤ãã®è¿½å ãã©ã¡ã¼ã¿ããµãã¼ããã¾ãã次ã®ãµã³ãã«ã¯ã20pxãã¨ã«ããã¯ãã»ããããåç´ã¹ã©ã¤ãã¼ãä½ãåºãã¾ãã
ï¼ã¤ã¾ãã¹ã©ã¤ãã¼ã»ãµã ãã¤ã«ã20pxãã¨ã«åãï¼var slider; function sliderInit() { slider = YAHOO.widget.Slider.getVertSlider("sliderbg", "sliderthumb", 0, 200, 20); } ï¼æ°å¤ã®åä½ã¯pxèæ¯ãã¯ãªãã¯ããããã¹ã©ã¤ãã¼ã»ãµã ãã¤ã«ããã©ãã°ãããã¨ãã¹ã©ã¤ãã¼ã¯èªåçã«ä¸çªè¿ãããã¯ã®ä½ç½®ãè¦ã¤ãã¦ç§»åãã¾ã
ï¼ããã¯ã®ã¤ã¡ã¼ã¸ããããªã人ã¯ãGoogleãã¼ã«ã«ã®ç¸®å°ºèª¿æ´ãã¼ãæãåºãã¦ãã ããã
2.Creating Slider Animation
If you include the Yahoo! Animation component in your web page, the slider animates when its background is clicked. The animation is a smooth "ease-in" transition unless you define tick marks for the slider. In that case the slider snaps to all tick marks on its way to the final destination.
Animation may not be desirable in some implementations. Some slider animations, for example using an image as a CSS background image for the slider thumb, may cause performance issues for some browsers (notably IE). In the case of the thumb performance can be improved by using a slider image <img src="..."> rather than a CSS background on the slider HTML element.
If you prefer not to use animation, you can disable animation either by omitting the reference to the Animation class, or by turning it off explicitly:
var slider; function sliderInit() { slider = YAHOO.widget.Slider.getHorizSlider("sliderbg", "sliderthumb", 100, 100); slider.animate = false; }2.ã¹ã©ã¤ãã¼ã®ã¢ãã¡ã¼ã·ã§ã³ãã¤ãã
ãã¼ã¸ã«Yahoo!Animationã³ã³ãã¼ãã³ããçµã¿è¾¼ãã§ããã°ãèæ¯ãã¯ãªãã¯ãããæã«ã¹ã©ã¤ãã¼ãã¢ãã¡ã¼ã·ã§ã³ãã¾ããã¹ã©ã¤ãã¼ã«ããã¯ãã»ãããã¦ããªãã®ãªããã¹ã ã¼ã¹ãªç§»åããã"ease-in"ã¢ãã¡ã¼ã·ã§ã³ã«ãªãã¾ãããã®å ´åãã¹ã©ã¤ãã¼ã¯çµç¹ã¾ã§å ¨é¨ã®ããã¯ã»ãã¼ã¯ãã¹ããããã¾ãã
ãease-in ãµã³ãã«ã
http://developer.yahoo.net/yui/slider/examples/slider.html
ã¢ãã¡ã¼ã·ã§ã³ã使ããªãæ¹ãããå ´åãããã¾ãããããã®ã¹ã©ã¤ãã¼ã»ã¢ãã¡ã¼ã·ã§ã³ã¯ãã©ã¦ã¶ã«å¼·ãè² è·ãããã¾ããä¾ãã°CSSã®background-imageã使ã£ãã¹ã©ã¤ãã¼ã»ãµã ãã¤ã«ã使ã£ããããªå ´åã§ããï¼ï¼©ï¼¥ã®å ´åã¯ç¹ã«ï¼ãã®ãããªã±ã¼ã¹ã§ã¯ãHTMLè¦ç´ ã®CSS backgroundã使ããªãã§ãã¹ã©ã¤ãã¼ãç»å<img src="">ããã¨ããã©ã¼ãã³ã¹ãæ¹åããããã¨ãããã¾ãã
ã¢ãã¡ã¼ã·ã§ã³ãç¡ãæ¹ãã好ã¿ã§ããããAnimationã¯ã©ã¹ã¸ã®åç §ãçç¥ãããããããã¯æ示çã«æ©è½ããªãã«ãã§ãã¾ãã
var slider; function sliderInit() { slider = YAHOO.widget.Slider.getHorizSlider("sliderbg", "sliderthumb", 100, 100); ã//æ示çã«ã¢ãã¡ã¼ã·ã§ã³æ©è½ããªãã¨ãã slider.animate = false; }
3.Customizing Events
The Slider component has an onChange event that is triggered when the slider thumb is moved. The onChange event provides the number of pixels the thumb has moved from the position it was in when the component was initialized.
var slider; function sliderInit() { slider = YAHOO.widget.Slider.getHorizSlider("sliderbg", "sliderthumb", 100, 100); slider.onChange = displayNewValue; } function displayNewValue(offsetFromStart) { // determine the actual value from the offset var newVal = (offsetFromStart + myStartVal * myScale); alert(newVal); }ã¤ãã³ããã«ã¹ã¿ãã¤ãºãã
Sliderã³ã³ãã¼ãã³ãã¯onChangeã¤ãã³ããç¨æãã¦ãã¾ããonChangeã¤ãã³ãã¯ã¹ã©ã¤ãã¼ã»ãµã ãã¤ã«ãåããããæã«çºçãã¾ããonChangeã¤ãã³ãã¯ã¹ã©ã¤ãã¼ã»ãµã ãã¤ã«ãä½ãã¯ã»ã«ç§»åããããæãã¦ããã¾ãã
var slider; function sliderInit() { slider = YAHOO.widget.Slider.getHorizSlider("sliderbg", "sliderthumb", 100, 100); //onChangeã¤ãã³ããèµ·ããã¨ãdisplayNewValueãå¼ã°ãã slider.onChange = displayNewValue; } function displayNewValue(offsetFromStart) { // å·®åï¼ãå®æ°ã§ä»£å ¥ var newVal = (offsetFromStart + myStartVal * myScale); alert(newVal); }ï¼displayNewValue()ã®ä¸ã§ä½¿ããã¦ãå¤æ°ãã©ãããåºã¦ãããã®ãªã®ãã¤ãã¤ãåããã¾ããï¼ã»Ïã»ï½ï¼