Home › Forums › JavaScript › Fadeout a echo message after couple of seconds
- This topic is empty.
-
AuthorPosts
-
August 15, 2018 at 3:15 am #275337pavdhuParticipant
Hello everybody,
I made a script but it isn’t working. When the user clicks the buttons 2 variables go into a database. The user get a message and that message should disappear after 3 seconds. But the message stays on the screen. I used
.fadeOut(3000)
but that seems not to be working.Anyone a solution? The used code can be seen when clicked on the codepen link.
August 15, 2018 at 4:31 am #275338BeverleyhParticipantTry loading the JS from page load, and bind the fadeOut effect/function to a click event when the button is pressed https://api.jquery.com/click/
August 15, 2018 at 5:05 am #275341AtelierbramParticipantAlternatively ISO an anonymous function pass a named function instead, and then call it after the jQuery library is inserted
echo '
'; echo ""; echo "function readyFn( jQuery ) {"; echo "$('#echo').fadeOut(3000);"; echo "};"; echo "";Je verzoeknummer is al aangevraagd en ontvangen door de DJ. Je wordt na 5 seconden automatisch teruggestuurd.
<!-- jquery library here --> $( document ).ready( readyFn ); </body> </html>
August 15, 2018 at 6:12 am #275343pavdhuParticipantCan you give a code example?
August 15, 2018 at 6:25 am #275344AtelierbramParticipanthttps://www.tehplayground.com/dxFNT9qyVyEx3WLq
Click “Save and Run” to render ;)
August 15, 2018 at 9:33 am #275357pavdhuParticipantHmm doens’t work with my code somehow. Tried it but the div shows en then disappeared without clicking the submit button.
August 15, 2018 at 9:54 am #275360AtelierbramParticipantThen better also do as @beverleyh wrote: bind a click event to the submit button and have that trigger the fadein/fadeout
August 15, 2018 at 10:07 am #275361AtelierbramParticipantIn the head of the document within style tags (or in a stylesheet):
#echo { opacity: 0; }
Down at the bottom of the document within script tags, just above the closing body tag:
$( "input[type='submit']" ).on( "click", function() { $( "#echo" ).css('opacity','1'); $( document ).ready( readyFn ); // console.log( "click" ); });
August 15, 2018 at 11:57 am #275366pavdhuParticipantSomehow still doens’t work. :(
August 15, 2018 at 1:15 pm #275371AtelierbramParticipantI adapted my code at https://www.tehplayground.com/2bmmLiLfNjRryYYd
Works for me …
August 16, 2018 at 3:44 am #275396pavdhuParticipantIt only works when you press the button 1 time. But then I need to reload the page in order to get the script working again.
August 16, 2018 at 1:50 pm #275419AtelierbramParticipantWhat have you tried so far?
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.