I
I
Ivan Baki-Borodov2017-10-26 18:33:23
css
Ivan Baki-Borodov, 2017-10-26 18:33:23

How to play/pause video on hover over another block (jQuery)?

there is a page, both halves of it have a video background. to be precise, this new.volna.dance is

needed to start playing the video that the cursor is hovering over. originally did this:

$(".hustlevideo").mouseover(function(){ 
$this.play(); 
});
$(".hustlevideo").mouseout(function(){ 
$this.pause(); 
});


but there was a problem - when you hover over a block that is located on top of the video, it, of course, stops.

moved the handler to the parent block, in which all the content is located, this is what happened:
$("#hustle").mouseover(function(){
$(".hustlevideo").play();
});
$("#hustle").mouseout(function(){
$(".hustlevideo").pause();
});


and now
I'm getting Uncaught TypeError errors: $(...).play is not a function and $(...).pause is not a function

What am I doing wrong and what should I do to make it work?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Timofey, 2019-07-30
@Timoffeus

It's not entirely clear, but maybe you just don't have enough block height? And isn't it easier to make a dropdown menu using js?

S
Stalker_RED, 2017-10-26
@lifelover2be

Instead of mouseover / mouseout use mouseenter / mouseleave.

$(...).play is not a function and $(...).pause is not a function
What am I doing wrong... ?

So you are trying to call the play() and pause() methods on a jQuery object.
Try $(...)[0].play()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question