views:

165

answers:

1

My problem is I can't get this jQuery slider to start from .1 to 10 in .1 increments and end (stop) at 10. Would like to pull this off without jQuery UI or jQuery tools.

I plan to have the hidden input value updated using the slider position then a button that says "VOTE".

I appreciate any help with this project. Thanks, Brandon.

Here's my generic demo page: http://videogameshowroom.com/slider.html

I'm trying to limit the slider to only move inside the "slider_container" div.I can't get the box to stop at the left and right?

<HTML>
<HEAD>
<script src="http://videogameshowroom.com/js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
$(function() {
    var sliderMouseDown = false;
    var count = 0;
    $("#slider").mousedown(function() {
        sliderMouseDown = true;
    });
    $(document).mousemove(function(evnt) {
        if (sliderMouseDown) {
            count = count + .1;
            $("#vote").html(count);
        }
    });
    $(document).mouseup(function() {
        if (sliderMouseDown)
        {
            $("#slider").focus();
            count = 0;
            sliderMouseDown = false;
        }
    });
});

var x1 = 0;
var drag = false;
$(document).ready(function(e){
$('#slider').mousedown(function(e){
e.preventDefault ();
x1 = e.pageX - parseInt($('#slider').css('left'));
drag = true;
})
$(document).mouseup(function(e){ drag = false; })
$(document).mousemove(function(e){ 
if(!drag) return
$('#slider').css('left',eval(e.pageX - x1)+'px')
})
});

//-->
</script>
<style type="text/css">
#slider_container { background: url(http://videogameshowroom.com/images/rating-slider-bg.jpg) repeat-x; width: 200px; height: 22px; background-color: #ffffff; display:block; position: relative; z-index: 1; }
#slider { background: url(http://videogameshowroom.com/images/rating-slider.jpg) no-repeat; width: 10px; height: 35px; top: -4px; position: absolute; left:0; cursor: pointer; cursor: hand; z-index: 99; }
</style>
</HEAD>
<BODY>
<br><br><br><br><br><br>

<center>
<div id="slider_container"><div id="slider"></div></div>
<div id="vote" class="vote"></div>
</center>

</BODY>
</HTML>
A: 

See What is the best method to reduce the size of my Javascript and CSS files? for some information about compressing your JavaScript files.

Nathan Taylor
Thanks. Took a different approach... Used jQuery interface.js to create slider snap.
Brandon Blanford