jQuery Variables, Functions, and Conditional Logic Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ธ.ค. 2024
  • Join my 2024 Bootcamp course experience learnwebcode.t...
    Learn how to use variables, conditional logic and functions to write flexible JavaScript.
    Have you put together a neat page infused with JavaScript awesomeness and want to move it from your computer to online so the world can see your JS chops? I’ve partnered with A Small Orange and can now offer my students 20% savings on any hosting plan. Hint: the shared “Small” plan is one of the best bangs for your buck around! p.asmallorange....
    Sign up for my newsletter to receive periodic webDev tips, tricks, resources and coupons. Join the list at learnwebcode.com/
    Follow LearnWebCode on Twitter for resources and updates:
    / learnwebcode
    Link to the example files shown in the video:
    learnwebcode.co...
    Link to the first JavaScript with jQuery lesson:
    • JavaScript and jQuery ...
    Note: The reveal effect shown in this lesson is not terribly useful in real world applications. Most tablets and smartphones cannot run code during the middle of a swipe scroll event so the effect will only run seamlessly on traditional computers / laptops. In short, I wouldn't necessarily use this effect on a production website, but it is a good playground for the sake of learning more about JavaScript variables, functions, and conditional logic.
    Also, I recommend not using jQuery's "animate" method whenever possible. Instead, you can simply use jQuery to add/remove a class at the desired moments, and instead use CSS transitions or animations. We'll cover this strategy in future lessons. The jQuery animate method is more dependable in older browsers and devices, but the CSS method provides smoother performance.
    Finally, we created the "on scroll reveal" functionality in this lesson from scratch as a learning exercise. If, however you're interested in a more robust and pre-built solution, be sure to search for the existing jQuery plugin named "jQuery WayPoints."

ความคิดเห็น • 107

  • @shadsluiter
    @shadsluiter 8 ปีที่แล้ว +14

    At 24:00 you need to include the css property 'position': relative to make it work:
    $(this).css( {
    "opacity": 0,
    'right':'700px',
    'position': 'relative'
    });

  • @justdnk777
    @justdnk777 9 ปีที่แล้ว

    I don't compliment very often, but you have a natural talent for teaching. Thank you so much, amazing.

  • @ATSPARIStransfers
    @ATSPARIStransfers 7 ปีที่แล้ว

    one of the best code teachers I've ever witnessed! congratulations, man! thanks so so much!!!

  • @rodgedulnuan1450
    @rodgedulnuan1450 9 ปีที่แล้ว

    I've watched this video tutorial many times to perfectly understand and pick up your strategies. You are a great teacher. Keep it up!

  • @curioquill
    @curioquill 7 ปีที่แล้ว

    The way you Teach and organize your content really makes sense and increases the understanding. Thank you for the good work.👍👍👍

  • @skeetemanricky
    @skeetemanricky 10 ปีที่แล้ว +2

    This has been one for the best tutorials I have seen.. you are a AWESOME teacher... keep up the good work...

  • @chrisdavis5440
    @chrisdavis5440 8 ปีที่แล้ว +6

    Just a heads up, this kind of caught me out there for a second. If you are having trouble with your direction parameter not functioning, remember that any html element that you apply the revealOnScroll function to must have a position: relative; in order to have the position animated. You can add it directly to your script like so...
    if(direction === "right") {
    $(this).css({
    "opacity" : 0,
    "position" : "relative",
    "right" : "700px"
    });
    } else {
    $(this).css({
    "opacity" : 0,
    "position" : "relative",
    "right" : "-700px"
    });
    }

  • @lens3973
    @lens3973 4 ปีที่แล้ว

    Perfect video To transition from my previous c++/c# knowledge into JavaScript and jQuery, thank you! Seems like Everytime I go to learn a new topic you have a video on it 😂

  • @enenotowitch628
    @enenotowitch628 4 ปีที่แล้ว

    Just a heads up, this kind of caught me out there for a second. If you are having trouble with your direction parameter not functioning, remember that any html element that you apply the revealOnScroll function to must have a position: relative; in order to have the position animated. You can add it directly to your script like so...
    if(direction === "right") {
    $(this).css({
    "opacity" : 0,
    "position" : "relative",
    "right" : "700px"
    });
    } else {
    $(this).css({
    "opacity" : 0,
    "position" : "relative",
    "right" : "-700px"
    });
    }
    15:37 - 19:55 -
    jQuery.fn.revealOnScroll = function(){
    return this.each(function(){

    })
    }

  • @ga7853
    @ga7853 5 ปีที่แล้ว

    I really do like your videos, this is the fourth time I watched this particular one, your way of teaching is really unique, Thank you so much for putting those videos out.

  • @countalucard1347
    @countalucard1347 4 ปีที่แล้ว

    This was like old but gold, 2020 random video checking really helpful til today :)

  • @shihab3930
    @shihab3930 8 ปีที่แล้ว

    You are the BOSS ! I decided to download your every tutorials.....

  • @ga7853
    @ga7853 8 ปีที่แล้ว

    This is just wonderful, plain sweet wonderful
    Thanks a million for just great tutorial, I watch it all online instead of download it
    so to appreciate the good hard work and skill you put in these series.
    Thanks again, God bless.

  • @martinewt
    @martinewt 8 ปีที่แล้ว +1

    First off, great tutorial(s), they are very well done. Second, regarding this specific one... why do you use the
    return this.each(function (){
    };
    inside the revealOnScroll function? I find everything works fine without it. So what's its use? Thanks for the videos!

  • @markandeygupta407
    @markandeygupta407 8 ปีที่แล้ว

    Great Tutorial. Thank you so much LearnWebCode. My lot of question solved in a single tutorial.

  • @NeddyRich
    @NeddyRich 8 ปีที่แล้ว

    You are a good teacher. I just might learn jquery after all! lol - It has been frustrating in the past not knowing how to implement certain things on my sites that I see other nice sites have. Soon, I will. You have good logic in your teaching.

  • @RapidPixel79
    @RapidPixel79 9 ปีที่แล้ว

    I don't know why you don't have more subscribers!!
    Great tutorial.

  • @ga7853
    @ga7853 6 ปีที่แล้ว

    Thank you so much for your unique way of explaining, I can not believe that I did not find you sooner, Thanks a million.

  • @andrewsgunn
    @andrewsgunn 10 ปีที่แล้ว

    Thank you so much for this training. I have just completes your "Web Design for Beginners: Real World Coding in HTML & CSS" course on Udemy and I feel great about it. Also the beginner version of jQuery tutorial which was EXACTLY what I was looking for. You have ex extremely clear way of teaching. :)

  • @lespantalonsfancie2434
    @lespantalonsfancie2434 6 ปีที่แล้ว +1

    I'm confused about the jQuery(".example-photo").revealOnScroll("left"); at 22.08, when the if/else code entered at 23.58 refers to "right'":700px and "right":-700px. In other words, when does "left" come into things? I spotted the two "rights" in the if/else when it was being entered and expected the code not to work, yet it did.

  • @SpicyboyCharlz
    @SpicyboyCharlz 10 ปีที่แล้ว

    Awesome! I was hoping you would do some javascript tutorials!
    You're the best, man!

  • @rosenivanov534
    @rosenivanov534 8 ปีที่แล้ว +1

    Amazing, absolutely love it! Thank you very much, this tutorial solved so much problems on my current project. Keep up the good work.

  • @platinumfox22
    @platinumfox22 10 ปีที่แล้ว +1

    Incredibly useful as usual. Thank you so much for your continued efforts and time. I like that you even took the time to explain, in the comments, why some of the things you showed us are less desirable in the 'real world', even if they make great teaching tools.

  • @sergethelight
    @sergethelight 9 ปีที่แล้ว

    A-MAZE-ING tutorial! So much value here alone! Thanks

  • @adamvaanunu8676
    @adamvaanunu8676 8 ปีที่แล้ว

    Again.. Amazing !! just great! :-)
    and another question,,
    what would you do to avoid passing strings? say you were typing mistakenly "letf"' then it won't pass the if=="left" statement and your code will do something you don't want.. ideas?

  • @thesaabbir
    @thesaabbir 8 ปีที่แล้ว

    Hello, Brad, I discovered you as my favorite and one of the top teachers in the web who knows how to teach. But I have a very important question after watching this tutorial. Why you went so far in jQuery without teaching JavaScript language itself? I can imagine how it would be great to watch your JavaScript 101 or fundamentals to gain the power of programming in JavaScript.

  • @nothing80400
    @nothing80400 5 ปีที่แล้ว

    TOM WON : I’ve been very upset and even the other vids with names like “love
    frequency “, “release serotonin/dopamine” or whatever sounds nice were
    actually not calming me. This particular sound has calmed my suicidal
    heart and actually made me feel lighter. KNOWLEDGE AND PLAY OF 20 FOR SHA . THE SUPER THING YOU NEVER SEEN BEFORE . KIDS GONE !

  • @shantanu35044
    @shantanu35044 7 ปีที่แล้ว +1

    mind blowing training speed and content. .. I am your fan !!!!

  • @1523dub
    @1523dub 10 ปีที่แล้ว +3

    Great video but I'm interested to know what type of HTML editor are you using?

    • @LearnWebCode
      @LearnWebCode  10 ปีที่แล้ว +2

      Thanks! The name of the text editor I use is TextMate.

  • @erasuz6078
    @erasuz6078 7 ปีที่แล้ว

    This tutorial is killing it !!!

  • @timetowatchstuff3737
    @timetowatchstuff3737 6 ปีที่แล้ว

    Hi there. Thank you for the tutorial. I am stuck at the bit near the end where you introduce the fading in from the left and right. I have looked over the code visible in the video many times and still cannot get the left and right fade-in to work.
    I know that you posted this four years ago but is there any chance you would post a direct link to the script.js file? So stuck people like me can compare direct to the source code to see what's missing?

    • @timetowatchstuff3737
      @timetowatchstuff3737 6 ปีที่แล้ว

      Found it! learnwebcode.com/tutorial-files/jquery-variables-functions/js/script.js

    • @timetowatchstuff3737
      @timetowatchstuff3737 6 ปีที่แล้ว

      Wow the source file is significantly different from that covered in the video!

  • @ChewiePower
    @ChewiePower 8 ปีที่แล้ว

    i see you used jQUERY(document) all of the other stuff I've seen jsut use the $(document) are they the same thing?

    • @asarrees
      @asarrees 8 ปีที่แล้ว

      josh jenkins Yup.

  • @ngoziize
    @ngoziize 10 ปีที่แล้ว

    A very clear introduction. Thanks!

  • @pointjabber
    @pointjabber 7 ปีที่แล้ว

    Are you planning on doing a Angular 4 tutorial?

  • @ShubhamRajdhar
    @ShubhamRajdhar 10 ปีที่แล้ว +1

    I can't thank you enough for all this knowledge! Just awesome!!

  • @mathiasmatanda8848
    @mathiasmatanda8848 5 ปีที่แล้ว

    Great tutorial man, so would you please reveal the css behind addClasses like animation-complete and hidden, on both if, anyone please

  • @LCNMGNMNT
    @LCNMGNMNT 8 ปีที่แล้ว

    Hi. FYI, the script file isn't on the webpage.

  • @ScarsofApathy
    @ScarsofApathy 2 ปีที่แล้ว

    This was very helpful for me, thank you!

  • @prashanshan7125
    @prashanshan7125 2 ปีที่แล้ว

    Happy new year 2023 ..Great tutorial I ever seen after long time.. today is 2023.01.01..thanks..

  • @anvisruili7579
    @anvisruili7579 10 ปีที่แล้ว

    thanks man! really useful, but some questions here:
    why windowscrollpobottom = windowheight + windowscrollpostop ?
    and what exactly windowscrollposbottom > objestoffsettop ?
    i know this is simple question, but still got a little confused

  • @ShawkatOsm
    @ShawkatOsm 7 ปีที่แล้ว

    Got trouble in my "$.fn.revealOnScroll = function ()".
    var objectOffset = $(this).offset();
    var objectOffsetTop = objectOffset.top;
    When calling "$(".sidebar").revealOnScroll();" the objectOffset.top returns incorrect value- I get the scrollTop value of the window which shouldn't be!
    Again when I scroll the page somewhere in the middle and refresh- then for that moment I get the actual "objectOffset.top" value of ".sidebar", but again when start scrolling- that value becomes scrollTop value. I am using "$(".status").html(windowScrollPosBottom + " / " + objectOffsetTop);" for debuggin!

  • @sepidehzarei9433
    @sepidehzarei9433 7 ปีที่แล้ว

    Hi, sorry I have problem with this line: if(!jQuery(".example-photo").hasClass("hidden")){ ,
    what is hidden in this line, is it a css class? we should write it ourself, How ? would any body answer my question?

    • @Kwisatsoundman
      @Kwisatsoundman 7 ปีที่แล้ว

      No, you don't have to write yourself any CSS class named "hidden" in your stylesheet, because this "hidden" css class added by our JavaScript function is totally empty and doesn't do anything, except telling the revealOnScroll() function to not hide this html element more than once, since this function is fired every time the user scrolls the page, otherwise the browser would crash by calling the same function again and again.
      Look at the source code of the script at:
      learnwebcode.com/tutorial-files/jquery-variables-functions/js/script.js
      We INITIALLY hide each element to which this function is applied thanks to the following part of the code:
      jQuery(this).css({
      "opacity" : 0,
      "right" : "700px",
      "position" : "relative"
      });
      And just after this code runs a first time, the "hidden" class is added one time:
      jQuery(this).addClass("hidden");
      But this code will never run a second time for the same html element, because it is wraped within the following conditional statement:
      if (!jQuery(this).hasClass("hidden")) { }
      (Don't forget that the exclamation point in front of jQuery means 'NOT'.
      In other words, ONLY IF the html element has NOT the class "hidden" already been added to it, run the code inside of me. Get it ?

    • @rr2100
      @rr2100 6 ปีที่แล้ว

      No need to write it, the code takes care of the css....

    • @babarbaig223
      @babarbaig223 6 ปีที่แล้ว

      "hidden" doesn't work if you are using Bootstrap, just replace word hidden from anything you like e.g "close" in the code and it will work fine.

  • @urdustoriespoetrycollectio976
    @urdustoriespoetrycollectio976 7 ปีที่แล้ว

    As always great tutorial 😍😍
    Very useful Love it.
    Thanks.

  • @atmosphereofpeaceandhope
    @atmosphereofpeaceandhope 7 ปีที่แล้ว

    i Like the simplicity with which you explain in youtube. Could you plz
    do a video on Python from basic to professional. (may be python and mysql in developing app like comment/opinion analysis Or any app) It would b very useful for my thesis work. thnx waiting...

  • @eladbarr
    @eladbarr 8 ปีที่แล้ว

    hi ..
    where can i found the files of this lesson ?
    thanks a lot

    • @ikhanuno
      @ikhanuno 6 ปีที่แล้ว

      Udemy

  • @fabianshamano5953
    @fabianshamano5953 10 ปีที่แล้ว

    Hi for the love of me I can't seem to apply this to the classes in my HTML I don't know why. I managed to do everything up until we got the offset part, things got hopeless from there on. I don't know why I cant successfully call div id's or classes for the code to work on them, I have followed every code and also tried to just take the final js file and simply call the elements from my HTML but to no avail, please help :-(

  • @jerrickhakim
    @jerrickhakim 6 ปีที่แล้ว

    You're a really good teacher

  • @studyshoot2161
    @studyshoot2161 5 ปีที่แล้ว

    getting exciting. Thanks Number Tow

  • @chengjinfei8139
    @chengjinfei8139 7 ปีที่แล้ว

    please tell me where's the link for source code ?

  • @HADEELHa-wp4tr
    @HADEELHa-wp4tr 8 ปีที่แล้ว

    great, its not working with me from the first scroll function *im sure of copying every letter u wrote*

  • @vivekpuri-08
    @vivekpuri-08 7 ปีที่แล้ว

    Instead of image , I am trying to animate with a paragraph in a fiddle.
    Why its not showing animation happening?

    • @babarbaig223
      @babarbaig223 6 ปีที่แล้ว

      It is working fine for me, I did try it with p, div etc.... make sure u r selected the tag correctly specially if they are nested into divs, "hidden" doesn't work if you are using Bootstrap, just replace word hidden from anything you like e.g "close" in the code and it will work fine... hopefully this will works.

  • @Greg-dn5rt
    @Greg-dn5rt 2 ปีที่แล้ว

    Please is the "JQuery.fn" at the start an obligation?

  • @globalentertainment3169
    @globalentertainment3169 7 ปีที่แล้ว

    Do I have access to this code?

  • @bordax20
    @bordax20 7 ปีที่แล้ว

    very good tutorial, well explained 'DO's and 'DON'T's. would be a shame not to press Subscribe button :D. looking forward on buying your course on Uemy. Good work, keep up!

  • @karthikeyasoft
    @karthikeyasoft 6 ปีที่แล้ว

    Your teaching awesome, give the html file for learning also

  • @mikemikic6226
    @mikemikic6226 7 ปีที่แล้ว

    Just saying, loved watching your tutorials. It has definitely enlightened my knowledge around web design and development for sure. Considered my signed up to your Udemy git course now!! ^_^

  • @_dmytro_275
    @_dmytro_275 7 ปีที่แล้ว

    thank you for this great lesson! !! I am looking for something like this

  • @johnconnor9787
    @johnconnor9787 2 ปีที่แล้ว

    2022 - Amazing tutorial

  • @cetti4405
    @cetti4405 9 ปีที่แล้ว

    Great and super easy to understand! Thanks....

  • @babarbaig223
    @babarbaig223 6 ปีที่แล้ว

    Awesome, well done buddy.

  • @andreescudragos680
    @andreescudragos680 8 ปีที่แล้ว

    more videos plz,you are great,thanks!

  • @sergeseva
    @sergeseva 10 ปีที่แล้ว +1

    Thanks heaps! Well explained with good examples. Cheers!

  • @chidambarchat
    @chidambarchat 10 ปีที่แล้ว

    Well explained with the nice examples really useful, Thanks man.

  • @prometheansujith5017
    @prometheansujith5017 8 ปีที่แล้ว +3

    $("p").text("this is such a great lecture, please don't stop adding videos like these. wishing you a very good success for the future");
    .

  • @filipracic9218
    @filipracic9218 9 ปีที่แล้ว +1

    Epic work m8, you have epic gr8 videos, can you make more gr8 Today In examples in Jquery/JavaScript?
    Note: If you are using Bootstrap don't use class hidden because it will still be display:none even with opacity: 1

    • @babarbaig223
      @babarbaig223 6 ปีที่แล้ว

      good catch Filip, had now clue as i am using Bootstrap lol, Thank alot.

  • @VijaySingh-op4hu
    @VijaySingh-op4hu 4 ปีที่แล้ว

    please make the video of jquery like this i have some list >>
    1. I want to need a bar when we scroll page the bar automatic increase width that tells how much page is left >>>
    2. I want sidebar when we scroll it sticky when reach top and remove sticky when footer close to sidebar this is i really want to please create video like that logical kind of (sidebar like udemy)

  • @MrTelekes
    @MrTelekes 10 ปีที่แล้ว

    Very well explained, Thank you very much

  • @phamluc2661
    @phamluc2661 9 ปีที่แล้ว

    thanks you very much for your video, i learn many things from video! :))))

  • @globalentertainment3169
    @globalentertainment3169 7 ปีที่แล้ว

    Just Amazing bro

  • @ivofrancisco357
    @ivofrancisco357 10 ปีที่แล้ว

    very good and logical!!

  • @leavethematrix9939
    @leavethematrix9939 8 ปีที่แล้ว

    Thank you, that was well done.

  • @ludgervisser8771
    @ludgervisser8771 8 ปีที่แล้ว

    .load method is depreciated and thus beginning should now be
    "jQuery(window).on("load", function()"
    to work with 3.x versions of jQuery

    • @Arttyor
      @Arttyor 7 ปีที่แล้ว

      You mean .load to replace .scroll? It doesnt work for me...

  • @emilywong4601
    @emilywong4601 5 ปีที่แล้ว

    Thanks for the review. I haven't used jquery in over 5 years and can't remember anything.

  • @tinycookie9492
    @tinycookie9492 9 ปีที่แล้ว +1

    Note to self: watch 1:00-6:00

  • @inception333
    @inception333 6 ปีที่แล้ว

    Variable windowHeight should be declared before, like below .. else it will take the whole document height
    var windowHeight = $(window).height();
    $(document).ready(function()

  • @ngoziize9961
    @ngoziize9961 10 ปีที่แล้ว

    Thanks, you are great!

  • @GyanAddict
    @GyanAddict 8 ปีที่แล้ว +1

    console.log("Thank you!");

  • @mozammelhaqmishuk
    @mozammelhaqmishuk 7 ปีที่แล้ว

    well done!

  • @duyanho8030
    @duyanho8030 5 ปีที่แล้ว

    this is how I say genius

  • @steveburrus5526
    @steveburrus5526 8 ปีที่แล้ว

    You DO know by now, I assume, thatr ins tead of writing "jQuery" you can just type the "$" sign? You did this video back in 2014 and it's now 2017. You can just write "$(function( ) {" to start off a Jquery file.

    • @LearnWebCode
      @LearnWebCode  8 ปีที่แล้ว +3

      Yep, you can use "$" and "jQuery" interchangeably. Back when I made this video I was using a CMS that included its own scripts and there was a conflict / battle for the "$" name so I was in the habit of playing it safe and using that instead of "$". Also nowadays, instead of using jQuery's document ready method it's simpler to just include your JS right before the closing "body" tag and just begin your JS file with whatever you need to do.

    • @up4life108
      @up4life108 8 ปีที่แล้ว

      +LearnWebCode but when you add a js-file and you use jQuery in it the browser will know that it has to load the jQuery scripts on its own or do I need to do something to tell it to?

    • @steveburrus5526
      @steveburrus5526 8 ปีที่แล้ว

      No yiou just have to make sure that you have the line "" right under the line pointing to the JQuery CDN file and also the 2 files must be in the same folder.

    • @up4life108
      @up4life108 8 ปีที่แล้ว

      Ok thanks!

    • @steveburrus5526
      @steveburrus5526 8 ปีที่แล้ว

      Diud I actually help you w. your problem?

  • @timetowatchstuff3737
    @timetowatchstuff3737 6 ปีที่แล้ว

    'jQuery(window).load' has been depreciated since jquery 1.8
    This 'jQuery(window).on('load', function()' is the recommended update from here stackoverflow.com/questions/38650315/why-window-load-is-not-working-in-jquery

  • @subscribeformore4110
    @subscribeformore4110 7 ปีที่แล้ว

    it so cool

  • @PGCshow
    @PGCshow 9 ปีที่แล้ว

    Great

  • @anixi85
    @anixi85 8 ปีที่แล้ว +1

    excuse me, man, but its so fuckin difficult (((