;(function($, window) {
var aside = $('.floating-aside'),
asideContent = aside.find('.floating-aside__content'),
asideWidth = 0,
asideHeight = 0,
stickTargetStart = $('.page-content'),
stickStart = 0,
stickEnd = 0,
stickTopOffset = 88,
stickBotOffset = 0,
pageYOffset = 0;
function setUp() {
asideWidth = aside.outerWidth();
asideHeight = aside.outerHeight();
stickStart = aside.offset().top - stickTopOffset;
stickEnd = aside.offset().top + stickTargetStart.outerHeight() - asideHeight - stickTopOffset;
aside.css({
height : asideHeight
});
asideContent.css({
width : asideWidth
});
}
function onScroll() {
pageYOffset = window.pageYOffset;
if (pageYOffset >= stickEnd) {
asideContent
.css({
position : 'absolute',
top : stickEnd - aside.offset().top + stickTopOffset
})
.removeClass('is-fixed-floated')
.addClass('is-absolute-floated');
return false;
}
if (pageYOffset <= stickStart) {
asideContent
.css({
position : 'relative',
top : 'auto'
})
.removeClass('is-absolute-floated is-fixed-floated');
return false;
}
if (pageYOffset >= stickStart && pageYOffset <= stickEnd) {
asideContent
.css({
position : 'fixed',
top : stickTopOffset
})
.removeClass('is-absolute-floated')
.addClass('is-fixed-floated');
return false;
}
}
if (aside.length > 0 && stickTargetStart.length > 0) {
setUp();
window.addEventListener('scroll', onScroll, supportsPassive ? { passive: true } : false);
window.addEventListener('resize', setUp, false);
$('#configNav .config-nav__list > li > a').on('shown.bs.tab', function (e) {
setUp();
});
}
})(jQuery, window);
overflow
для iOs устройств-webkit-overflow-scrolling : touch;
$.preventScrolling = function(selector) {
$.each($(selector), function(index, element) {
var element = $(element),
scrollDiff = null,
wheelDelta = null,
scrollTop = null;
element.on('mousewheel DOMMouseScroll', function(event) {
/**
* направление колёсика мыши (-1 вниз, 1 вверх)
*
* нормализация определения направления прокрутки
* (firefox < 0 || chrome etc... > 0)
* (event.originalEvent.detail < 0 || event.originalEvent.wheelDelta > 0)
*/
wheelDelta = (event.originalEvent.detail < 0 || event.originalEvent.wheelDelta > 0) ? 1 : -1;
scrollDiff = element[0].scrollHeight - element.outerHeight(); // высота скролла
scrollTop = element[0].scrollTop; // позиция скролла
if ((scrollTop >= scrollDiff && wheelDelta < 0) || (scrollTop <= 0 && wheelDelta > 0)) {
event.preventDefault();
}
});
});
};
$.preventScrolling('.scroller-block_first, .scroller-block_second');
<div class="askquestion"><b>myname</b></div>
<div name="myname">Click</div>
$('.askquestion').click(function () {
var invtext = $(this).html();
// тут удаляем все HTML теги из строки
var StrippedString = invtext.replace(/(<([^>]+)>)/ig,"");
$('[name = ' + StrippedString + ']').css('display','block');
});
<?php
function ajax_auth_init(){
wp_register_script('ajax-auth-script', get_template_directory_uri() . '/js/ajax-register-script.js', array('jquery') );
wp_enqueue_script('ajax-auth-script');
wp_localize_script( 'ajax-auth-script', 'ajax_auth_object', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'redirecturl' => home_url(),
'loadingmessage' => __('Sending user info, please wait...')
));
// Enable the user with no privileges to run ajax_register() in AJAX
add_action( 'wp_ajax_nopriv_ajaxregister', 'ajax_register' );
}
// Execute the action only if the user isn't logged in
if (!is_user_logged_in()) {
add_action('init', 'ajax_auth_init');
}
function ajax_register(){
// First check the nonce, if it fails the function will break
check_ajax_referer( 'ajax-register-nonce', 'security' );
// Nonce is checked, get the POST data and sign user on
$info = array();
$info['user_nicename'] = $info['nickname'] = $info['display_name'] = $info['first_name'] = $info['user_login'] = sanitize_user($_POST['username']) ;
$info['user_pass'] = sanitize_text_field($_POST['password']);
$info['user_email'] = sanitize_email( $_POST['email']);
// Register the user
$user_register = wp_insert_user( $info );
if ( is_wp_error($user_register) ){
$error = $user_register->get_error_codes() ;
if(in_array('empty_user_login', $error))
echo json_encode(array('loggedin'=>false, 'message'=>__($user_register->get_error_message('empty_user_login'))));
elseif(in_array('existing_user_login',$error))
echo json_encode(array('loggedin'=>false, 'message'=>__('This username is already registered.')));
elseif(in_array('existing_user_email',$error))
echo json_encode(array('loggedin'=>false, 'message'=>__('This email address is already registered.')));
} else {
auth_user_login($info['nickname'], $info['user_pass'], 'Registration');
}
die();
}
jQuery(document).ready(function($) {
$('#register .submit_button').on('click', function(event) {
var action = 'ajaxregister';
username = $('#signonname').val();
password = $('#signonpassword').val();
email = $('#email').val();
security = $('#signonsecurity').val();
$.ajax({
type: 'POST',
dataType: 'json',
url: ajax_auth_object.ajaxurl,
data: {
'action': action,
'username': username,
'password': password,
'email': email,
'security': security
},
success: function (data) {
$('.status').text(data.message);
if (data.loggedin == true) {
document.location.href = ajax_auth_object.redirecturl;
}
}
});
event.preventDefault();
});
});
// отпадет необходимость в этом коде
$('#navMenu span').hover(function(){
$(this).css({
"transform": "translate(-30px,0px)",
"-webkit-transform": "translate(-30px,0px)",
"-o-transform": "translate(-30px,0px)",
"-moz-transform": "translate(-30px,0px)"
});
}, function(){
$(this).css({
"transform": "translate(0px,0px)",
"-webkit-transform": "translate(0px,0px)",
"-o-transform": "translate(0px,0px)",
"-moz-transform": "translate(0px,0px)"
});
}
);
// jquery код
$(document).ready(function() {
var example = $('.example'),
exampleHeight = $('.example-height');
exampleHeight.on('keyup change', function() {
example.css({
height: exampleHeight.val()
});
});
});
<select name="my-select">
<option>...</option>
<option>...</option>
<option>...</option>
</select>
// jQuery
var myDynamoSelect = $('select[name="my-select"]');
$.ajax({
type: "POST",
url: "some.php",
data: "name=John&location=Boston",
success: function ( data ) {
// empty() чистим HTML в селект
// html(data) вставляем в select то что ответил сервер (<option>...</option>)
// пример ответа: <option>...</option><option>...</option><option>...</option>
myDynamoSelect.empty().html(data);
}
});