Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9144343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:14:46+00:00 2026-06-17T10:14:46+00:00

This is my first html5 project, getting the gist of it, need a bit

  • 0

This is my first html5 project, getting the gist of it, need a bit of help. I used a jquery UI slider to send an opacity value to the canvas and it works quite nicely… but I can’t get the image to completely turn off when the slider is in the off position with a value of zero. Here is a fiddle of what I’m trying to do : http://jsfiddle.net/N6wZZ/2/

Here is my JS:

$("#slider").slider({
    animate: true,
    range: "min",
    value: 0,
    min: 0,
    max: 0.9,
    step: .01,
    create: function (event, ui) { 
        var opacityValue = '0.0';
        canvasFunction(opacityValue);
    },
    slide: function (event, ui) { 
         $('#hiddenField').attr('value', ui.value);
         $("#slider-result").html(ui.value);
         var opacityValue = $('#hiddenField').val();
         if (opacityValue == 0) {
            var opacityValue = 0;
            var workAroundVar = 300;
            var workAroundVarTwo = 0;
            canvasFunction(opacityValue, workAroundVar, workAroundVarTwo);
        } 
        else {
            var workAroundVar = 0;
            var workAroundVarTwo = 300;
            canvasFunction(opacityValue, workAroundVar, workAroundVarTwo);
        }
    }     
});
function canvasFunction(opacityValue, workAroundVar, workAroundVarTwo){
    var canvas = document.getElementById("myCanvas");
    var ctx = canvas.getContext("2d");
    var img1 = loadImage('http://moosepic.com/test2.png', main);
    var img2 = loadImage('http://moosepic.com/test.png', main);


    var imagesLoaded = 0;

    function main() {
      imagesLoaded += 1;

      if (imagesLoaded == 2) {
        // composite now
        ctx.drawImage(img1, 0, 0, 300, 300);

          ctx.globalAlpha = opacityValue;
          ctx.drawImage(img2, workAroundVar, workAroundVar, workAroundVarTwo, workAroundVarTwo);

      }
    }

    function loadImage(src, onload) {
      var img = new Image();

      img.onload = onload;
      img.src = src;

      return img;
    }

}

as you can see I’ve made a bunch of workarounds to turn off the second image or just knock it out of the canvas. Any help would be awesome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:14:48+00:00Added an answer on June 17, 2026 at 10:14 am

    Silas. I’ve taken a look at your jsFiddle. I forked it and made some changes/improvements to your approach and I think it accomplishes your goal:

    http://jsfiddle.net/3LJsX/7/

    Here is the approach I took (which is pretty close to yours, just some minor differences):

    1. Load our first image
    2. Load our second image in the onLoad function of the first image
    3. Create our slider in the onLoad function of the second image
    4. The slider’s create and update methods both call the refreshVisuals function which updates the value of the slider div and updates the canvas

    A main difference is in the draw function which was called canvasFunction in your example. In my draw function, I make sure to:

    1. Clear the canvas each time we draw
    2. Make sure the alpha is at 1 when we draw our first image with the tree
    3. Draw the tree image
    4. Update the alpha to be whatever the current value is for the slider
    5. Draw our tiedie image

    That should be it! Let me know if you have any questions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This first bit works: $my_id = 617; $post_id_7 = get_post($my_id); $title = $post_id_7->post_excerpt; echo
The Benchmark: http://jsperf.com/substringing So, I'm starting up my very first HTML5 browser-based client-side project.
Hi this is my first time trying to push a project up to Heroku
My ruby version is 1.9.1. this is first project in ruby i am trying
I am trying to make kind of online gallery, this is first .html doc
First off the html row looks like this: <tr class=evenColor> blahblah TheTextIneed blahblah and
Here's my HTML. Apologies for formatting - this is my first-ever question! <div id=Template>
this is HTML <p>x1</p> <p>x2</p> and i want css to select first < p>
First of all, I found this: Objective C HTML escape/unescape , but it doesn't
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.