Created
October 1, 2012 20:44
-
-
Save zenman/3814300 to your computer and use it in GitHub Desktop.
Touch Scrollable Image Area WP Widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* set default styles for draggable area */ | |
.drag-mask { | |
float: left; | |
width: 100%; | |
height: 120px; | |
overflow: hidden; | |
} | |
.drag-container { | |
width: 2000px; | |
} | |
.draggable { | |
position: relative; | |
width: 2000px; | |
margin-left: -1000px; | |
height: 110px; | |
} | |
.drag-slides { | |
position: absolute; | |
width: 100%; | |
z-index: -1; | |
img { | |
padding: 0 10px; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this to your wp content: | |
[slider-bar posts='100' category='1'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add scrolling functionality | |
// requires jQuery UI and jQuery Touch Punch: | |
// http://jqueryui.com/ | |
// http://touchpunch.furf.com/ | |
$(window).load(function() { | |
var contain = $('.drag-container'); | |
var mask = $('.drag-mask') | |
var drag = $('.draggable'); | |
var clicked = false; | |
//implement dragging | |
try { | |
drag.draggable({ | |
axis: 'x', | |
containment: '.drag-container' | |
}); | |
} catch (e) { | |
return false; | |
} | |
//set the size of the content | |
var imgWidth = null; | |
var screenWidth = mask.width(); | |
drag.find('img').each(function(){ | |
imgWidth += ($(this).width() + (parseInt($(this).css('margin-right')) * 2) + 15); | |
contain.width(imgWidth + screenWidth); | |
drag.width(imgWidth + screenWidth); | |
drag.css('margin-left',(imgWidth * -1 + screenWidth - 100)); | |
drag.css('left',imgWidth - screenWidth); | |
}); | |
$(window).resize(function(){ | |
screenWidth = mask.width(); | |
drag.css({ | |
'margin-left':(imgWidth * -1 + screenWidth - 100), | |
'left': (imgWidth - screenWidth) | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add this to your functions.php file | |
/* | |
* Show slider bar. | |
*/ | |
function slider_bar_function($atts){ | |
extract(shortcode_atts(array( | |
'posts' => 100, | |
'category' => 1 | |
), $atts)); | |
global $post; | |
$images = null; | |
$args = array( 'numberposts' => $posts, 'category' => $category ); | |
$myposts = get_posts( $args ); | |
foreach( $myposts as $post ) { | |
setup_postdata($post); | |
$images .= get_the_post_thumbnail($post->ID); | |
} | |
$return_string = ' | |
<div class="drag-mask inset col12"> | |
<div class="drag-container"> | |
<div class="draggable"> | |
<div class="drag-slides"> | |
' . $images . ' | |
</div> | |
</div> | |
</div> | |
</div>'; | |
return $return_string; | |
} | |
add_shortcode('slider-bar', 'slider_bar_function'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment