(function($){
// A collection of elements to which the tripleclick event is bound.
var elems = $([]),
// Initialize the clicks counter and last-clicked timestamp.
clicks = 0,
last = 0;
// Click speed threshold, defaults to 500.
$.tripleclickThreshold = 500;
// Special event definition.
$.event.special.tripleclick = {
setup: function(){
// Add this element to the internal collection.
elems = elems.add( this );
// If this is the first element to which the event has been bound,
// bind a handler to document to catch all 'click' events.
if ( elems.length === 1 ) {
$(document).bind( 'click', click_handler );
}
},
teardown: function(){
// Remove this element from the internal collection.
elems = elems.not( this );
// If this is the last element removed, remove the document 'click'
// event handler that "powers" this special event.
if ( elems.length === 0 ) {
$(document).unbind( 'click', click_handler );
}
}
};
// This function is executed every time an element is clicked.
function click_handler( event ) {
var elem = $(event.target);
// If more than `threshold` time has passed since the last click, reset
// the clicks counter.
if ( event.timeStamp - last > $.tripleclickThreshold ) {
clicks = 0;
}
// Update the last-clicked timestamp.
last = event.timeStamp;
// Increment the clicks counter. If the counter has reached 3, trigger
// the "tripleclick" event and reset the clicks counter to 0. Trigger
// bound handlers using triggerHandler so the event doesn't propagate.
if ( ++clicks === 3 ) {
elem.trigger( 'tripleclick' );
clicks = 0;
}
};
})(jQuery);
Я использую этот код тройного щелчка для моего файла JS и помещаю функцию на кнопку в моей навигационной панели. Я использую эту функцию для изменения логического варианта.
$(function()
{
$("#SNLCK").bind("tripleclick", function() {
if(SNLOCK)
{
SNLOCK= false;
}
else
{
SNLOCK= true;
}
alert( 'I have been triple-clicked! '+SNLOCK);
});
});
и в html я использую if (SNLOCK). когда я делаю это, SNLOCK был изменен, но HTML не меняется с ним .. как я могу изменить веб-сайт, когда был изменен логический.
Я делаю это, чтобы исчезнуть некоторые кнопки в навигационной панели, когда я нажимаю три раза на какую кнопку. Спасибо за помощь.
-1
דור סויסה
Новые вопросы
javascript
По вопросам программирования на ECMAScript (JavaScript / JS) и его различных диалектах / реализациях (кроме ActionScript). Включите все соответствующие теги в свой вопрос; например, [node.js], [jquery], [json] и т. д.