I have a slide show program called Jssor which also uses jQuery. I have links inside the slide show which invoke Fancybox3 to display a text box describing that slide. I need the slide show to pause while the focus is on Fancybox. Jssor has a method called $Pause and $Play and I can get it to work (outside of the jQuery class) by using buttons (manually clicking.) The main issue is that I need it to work without user interaction. My plan is to put the code into Fancybox.js so it will pause/play the slide show automatically. I know almost nothing about JavaScript so please keep it simple.
I left out (below) a bunch of code thinking I would make this simple and hoping it’s not needed for this question. This code does work, I just need to know how to make/invoke the last line (using JS not HTML) without user input.
<script type="text/javascript">
jQuery(document).ready(function ($) {
// A bunch of code
//...........................
var jssor_1_slider = new $JssorSlider$("jssor_1", jssor_1_options);
function Play() {
jssor_1_slider.$Play();
};
function Pause() {
jssor_1_slider.$Pause();
};
$("#playButton").click(Play);
$("#pauseButton").click(Pause);
};
</script>
// HTML
<input id="playButton" type="button" value="Play" />
<input id="pauseButton" type="button" value="Pause" />
Callbacks are designed for purposes like this. Example:
$('[data-fancybox="images"]').fancybox({
onInit : function() {
jssor_1_slider.$Pause();
},
afterClose : function() {
jssor_1_slider.$Play();
}
});
Obviously, this code should go after you have created jssor_1_slider variable.
Related
i found a very simple javascript function for a slideshow (here).
It works perfectly, but i want to change something about the control buttons. Right now, the play/pause button displays it's own name, like this:
<button class="controls" id="pause">Pause</button>
The javascript is set to run a function called pauseSlideshow under certain circumstances which not only pauses/resumes the slideshow, but also changes the displayed content of the button from "pause" to "play":
var playing = true;
var pauseButton = document.getElementById('pause');
function pauseSlideshow() {
pauseButton.innerHTML = 'Play';
playing = false;
clearInterval(slideInterval);
}
now, what i want to do is to leave the button empty and work width background images, and to do that i planned to do a simple class swap whenever the pauseSlideshow function is triggered. So, first i added a class called pause to the button with the desired background image set in the style:
<button class="controls pause" id="pause"></button>
and next i was going to do something like this:
var playing = true;
var pauseButton = document.getElementById('pause');
function pauseSlideshow() {
pauseButton.removeClass('pause');
pauseButton.addClass('play');
playing = false;
clearInterval(slideInterval);
}
(where play is another class with a different background image). Sufficient to say, as soon as pauseSlideshow runs, the function crashes. I'm writing something wrong or in the wrong place, but i know that the approach is viable.
please, can anybody point out the error?
EDIT:
Use $(pauseButton).removeClass('pause'); and
$(pauseButton).addClass('play');. addClass and removeCalss are jQuery
methods. And you need to add jQuery reference too. – user3698428
document.getElementById("pause") does not return a jQuery element.
.removeClass() and .addClass() are jQuery functions. So basically you
are trying to call jQuery functions on a non-jQuery element and it's
throwing an error. Change it to var pauseButton = $("#pause"); or
$(pauseButton).removeClass(...); $(pauseButton).addClass(...);
when i try either way, console returns: Uncaught ReferenceError: $ is not defined
When working in pure javascript, you should use this to add or remove class:
pauseButton.classList.remove('pause');
pauseButton.classList.add('play');
https://developer.mozilla.org/en-US/docs/Web/API/Element/classList
is there any one who is familiar with YUI jQuery frame work ?? i need very little help
please take the look at below code
It works perfect but the inputClick() is called when i press any button left or right but i dont want button, i want to call function when page loads means automatically
please help me some one.
in short I want to call inputclick(e){......} automatically when page load
i heard about domready function which is same like JQuery's document.ready function
so how should i call inputClick(e)??
please take look at this ::
<section id="btns">
<p>
<input type="button" value="Left">
<input type="button" value="Right">
</p>
</selection>
<script src="http://yui.yahooapis.com/3.5.1/build/yui/yui-min.js"></script>
<script>
document.querySelector('#btns').addEventListener("click", inputClick, false);
function inputClick(e){
var a = e.target.value;
window.alert(a); // displays Left or Right button value
}
</script>
i tried inputClick(Left); and inputClick(Roght); but do nothing :(
What i need is when page load ::
rnd = random(2);
switch(rnd)
case 1:
inputClick(Left);
case 2:
inputClick(Right);
i DONT want button or eventlistener
I hope this helps. http://jsfiddle.net/Rh7Ju/1/
Know that anything in the YUI().use() will execute when the DOM is ready.
YUI().use('node', 'event', function (Y) {
function inputClick(button_value) {
alert(button_value);
}
// called when the buttons are clicked
Y.one('#btns').on('click', function (e) {
inputClick(e.target.get('value'));
}, 'input');
inputClick('Right'); // called when the dom is ready.
});
After I looked at your question again, is seems like you are trying to randomly select a button and alert its value. So, maybe this is more what you're looking for?
http://jsfiddle.net/Rh7Ju/2/
Anyway, happy coding.
I am still new to javascript.
I have an application that has two buttons on the page. One is a cpu_vs_player button that displays one game and the other is a player_vs_player button that displays a different game. The problem is that all the code is located in one application.js file. There is no need to load the player_vs_player on $(document).ready(function(){}); if I were to play cpu_vs_player.
Any ideas on how I can get them to load only if I chose that game? (I am only using one route with all the information being hidden / shown based on the click).
The document.ready is nothing more than the moment after the page has rendered and the document needs to be populated with event listeners. Frankly there are multiple way of skinning this cat.
You can either do the jQuery way where you keep javascript and HTML divided:
<button id="button1">cpu_vs_player</button>
<button id="button2">player_vs_player</button>
And for JavaScript:
Assuming you have a function for each gameplay:
function cpu_vs_player() {
// start the game
}
function player_vs_player() {
// need another player
}
Add event listeners the jQuery way:
$(document).ready(function() {
$("#button1").click(function() {
cpu_vs_player();
});
$("#button1").click(function() {
player_vs_player();
});
});
OR you could use the method #Techstone shows you, though you could do it more direct. It all works though.
<button onclick="javascript:cpu_vs_player();">cpu_vs_player</button>
<button onclick="javascript:player_vs_player();">player_vs_player</button>
Adding another option you can apply
In Javascript:
var Main = {
cpu_vs_player: function() {
alert("start cpu_vs_player");
},
player_vs_player: function() {
alert("start player_vs_player");
}
}
In your HTML:
<button onclick="javascript:Main.cpu_vs_player();">cpu_vs_player</button>
<button onclick="javascript:Main.player_vs_player();">player_vs_player</button>
And yes, there is more ... ;-)
image that your two button and js definition like below
function LetsRock(Playmate) {
....
}
<input type='button' value='cpu_vs_player' id='cpu_vs_player' onclick='javascript:LetsRock(this.id);' />
<input type='button' value='player_vs_player' id='player_vs_player' onclick='javascript:LetsRock(this.id);' />
Try to use the function with parameters (i.e. 0 to cpu v/s player, 1 to player v/s player), and send from the menu page to the $(document).ready(function(){});
I am creating a game and need help with the Start button. I don't want the standard "Start" button JavaScript creates. I want to use my own image that reads "Start", as the actual start button. This is the code I used:
In the script tags:
function theButton ()
{
document.getElementById("button").src="images/button.png";
}
In the body:
<button onclick="button"()"><img src="images/button.png"></button>
Although this did work, the image is just plastered on top of the standard gray button JavaScript creates. I figured a function would be necessary, but I am not quite sure how to get that to go along with it, or if it is needed. Appreciate the help.
Use this html:
<img src="images/button.png" onclick="start();" />
And the script:
function start() {
// do something here
}
Ok, I'm trying to modify some already written jQuery - as background, I know Javascript decently, but I'm only so-so with jQuery. My understanding of this code is that there's a scrolling bar, which will change every 6 seconds. I am unsure if there's any video specific code in here though - right now the scrollbar has a video embedded on one of the panes, which is clicked on.
What I am trying to do, is set up an image (currently inside <div class=vid>, not shown), which when it is clicked, will stop the paning, UNTIL one of the buttons at the bottom is clicked, and it will also play a flash video.
Here's the code:
<script type="text/javascript">
jQuery(document).ready(function() {
var scroll_item = jQuery("#chained").scrollable({circular: true, mousewheel: false}).navigator().autoscroll({
interval: 6000,
autoplay: false,
autopause: false
});
window.scroll_control = scroll_item.data("scrollable");
scroll_control.play();
var $playBtn = $('#p-p-btn');
$playBtn.click(function(){
if($(this).hasClass('play')){
$(this).addClass('pause');
$(this).removeClass('play');
scroll_control.play();
} else if($(this).hasClass('pause')) {
$(this).addClass('play');
$(this).removeClass('pause');
scroll_control.stop();
};
});
jQuery('#chained').hover(
function() { scroll_control.stop(); },
function() {
if ($playBtn.hasClass('pause')) {
scroll_control.play();
}
}
);
});
</script>
I believe all I have to do is add a condition which will determine if the image has been clicked (it is in <div class=vid>, but I am going to give it an id as well probably), which will turn the paning off (perhaps by "clicking" the play/off button?), and it will also launch the video with an auto play setting.
Does that sound accurate?
How would I turn the paning off?
I don't fully understand the code, because i don't know the whole context.
But try to add this in your document ready:
$("#YOURIMAGEID").bind("click",function(){
scroll_control.stop();
$('#p-p-btn').addClass('play');
$('#p-p-btn').removeClass('pause');
//other logic
});