Created
April 30, 2017 04:18
-
-
Save AnatoliyAkhmatov/c2ebd1d30d509181478de6e09dd3a5f6 to your computer and use it in GitHub Desktop.
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
<?php | |
$args = array( | |
'orderby' => 'ID', | |
'order' => 'ASC', | |
'post_type' => 'instructor', | |
'post_status' => 'publish', | |
); | |
$loop = new WP_Query( $args ); | |
?> | |
<?php while ( $loop->have_posts() ) : $loop->the_post();?> | |
/** | |
* Gallerys | |
*/ | |
add_action( 'init', __NAMESPACE__ . '\\create_gallery_post_type' ); | |
function create_gallery_post_type() | |
{ | |
$labels = array( | |
'name' => 'Галереи', | |
'singular_name' => 'Галерея', | |
'add_new' => 'Добавить галерею', | |
'add_new_item' => 'Добавить новую галерею', | |
'edit_item' => 'Редактировать галерею', | |
'new_item' => 'Новая галерея', | |
'view_item' => 'Смотреть галерею', | |
'search_items' => 'Найти галерею', | |
'not_found' => 'Галерея не найдена', | |
'not_found_in_trash' => 'В корзине гелерей не найдено', | |
'parent_item_colon' => '', | |
'menu_name' => 'Галереи' | |
); | |
register_post_type('gallery', array( | |
'labels' => $labels, | |
'public' => true, | |
'has_archive' => true, | |
'supports' => array('title','editor', 'thumbnail', 'excerpt','custom-fields' ), | |
'menu_icon' => 'dashicons-format-gallery', | |
//'show_in_nav_menus' => true | |
)); | |
} | |
/ gallery carousel | |
(function($) { | |
$("img, a").on("dragstart", function(event) { event.preventDefault(); }); | |
var gallery = document.querySelector('.gallery'); | |
gallery.addEventListener('mousedown', start); | |
var x; | |
var l = 0; | |
var windowWidth = document.documentElement.clientWidth; | |
var galleryWidth = gallery.querySelector('.items-wrap').offsetWidth; | |
function start(e) { | |
x = e.clientX; | |
windowWidth = document.documentElement.clientWidth; | |
galleryWidth = gallery.querySelector('.items-wrap').offsetWidth; | |
if (galleryWidth < windowWidth) { | |
return; | |
} | |
document.addEventListener('mousemove', move); | |
document.addEventListener('mouseup', end); | |
} | |
function move(e) { | |
var left = -(x - e.clientX) + l; | |
// if (left > 0) { | |
// left = 0; | |
// } else if (Math.abs(left) + windowWidth > galleryWidth) { | |
// left = -(galleryWidth - windowWidth); | |
// } | |
// console.log(Math.abs(left) + windowWidth ); | |
crossTranform(gallery, 'translate('+ left + 'px, 0)'); | |
} | |
function crossTranform(el, value) { | |
el.style.MozTransform = value; | |
el.style.WebkitTransform = value; | |
el.style.OTransform = value; | |
el.style.MsTransform = value; | |
el.style.transform = value; | |
} | |
function end(e) { | |
try { | |
l = +getComputedStyle(gallery).transform.match(/matrix\(\d+, ?\d+, ?\d+, ?\d+, ?(\d+)/)[1]; | |
} catch(err) { | |
l = +getComputedStyle(gallery).transform.match(/matrix\(\d+, ?\d+, ?\d+, ?\d+, ?(-\d+)/)[1]; | |
} | |
if (l > 0) { | |
console.log('>'); | |
l = 0; | |
crossTranform(gallery, 'translate(0, 0)'); | |
gallery.style.transition = 'all 300ms'; | |
setTimeout(function() { | |
gallery.style.transition = ''; | |
}, 320); | |
} else if (Math.abs(l) + windowWidth > galleryWidth) { | |
console.log('<'); | |
l = -(galleryWidth - windowWidth) | |
crossTranform(gallery, 'translate('+ l +'px, 0)'); | |
gallery.style.transition = 'all 300ms'; | |
setTimeout(function() { | |
gallery.style.transition = ''; | |
}, 320); | |
} | |
document.removeEventListener('mousemove', move); | |
document.removeEventListener('mousedown', end); | |
} | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment