PDA

View Full Version : Side Push Menu v1.1 - Stop Media playing when menu is closed?



Neil1
07-06-2019, 10:52 PM
1) Script Title: Side Push Menu v1.1

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex1/pushmenu.htm

3) Describe problem: Not so much a problem as a query if something is possible. I am using multiple instances of the side push menu to be able to bring in additional content if wanted at various points on my site... A couple of these include videos. Now the problem is when the pushmenu screen is dismissed the video keeps playing (Unless the user thinks to manually stop it) leaving distracting audio playing.

What I was hoping to achieve is something that stops or better yet pauses the video when the menu is closed. I have no idea what I'm doing with javascript but I am assuming (Hoping!) there is some way to attach a "stop all media" code to activate when the menu is in the closed position? I don't want autoplay or anything so no need to have a play on open / stop on close function, just something that tells all media within the push section to stop when it is closed... (Or if easier just all media anywhere on the site, there are no videos outside of the content that slides in to be affected, and videos in other pushed content should already be stopped anyway)

Hope I've explained this well enough, and that a solution is a) possible, and b) hopefully simple to implement!

molendijk
07-07-2019, 08:32 PM
In pushmenu.js there's this line:

.find('.closebutton').on('click', function(e){thismenu.toggle('closed') })
Replace it with something like:

.find('.closebutton').on('click', function(e){document.getElementById('myVideo').pause(); thismenu.toggle('closed') })
where myVideo is the id for the video tag.

Neil1
07-07-2019, 08:59 PM
Awesome! Works perfectly (-ish) thank-you very much!

There is one little tweak I'd like if you are able and don't mind helping again?

I was using a modified version of pushmenu that also allows the pushed content to be closed with a swipe on touch screens, is it possible to do the same if it is closed that way?

http://www.dynamicdrive.com/forums/showthread.php?77335-Addition-of-swipe-functionality-to-Side-Push-Menu&highlight= < This thread has the amended code I am using to add the swipe function, hopefully it is just a simple switching of a line or two as the original one was

And once again many thanks for the help you've already provided :)

molendijk
07-07-2019, 09:35 PM
I found these lines in ddadmin's script:

swipeStatus: function(event, phase, direction, distance){
if (phase == 'end' && direction == 'left')
thismenu.toggle('closed')
}

Replace that part with this:

swipeStatus: function(event, phase, direction, distance){
if (phase == 'end' && direction == 'left')
document.getElementById('myVideo').pause(); thismenu.toggle('closed')
}

It might work.

Neil1
07-07-2019, 09:49 PM
Thanks but no luck I'm afraid, it keeps playing when closed if you swipe it closed... But many thanks for trying, it was appreciated :)