How to show a portion of canvas - javascript

My canvas has a background image. That image has different part such as level-1,level-2 etc. I will create few buttons. When button-1 is clicked only show level-1 portion of background image and hide other levels. Similarly for button-2 is clicked only show level-2. For example the background could look like this image:

Related

How do you make a portion of the image undraggable?

I'm working on a project that has some draggable content in it. All of the images that are draggable have portion that are transparent and overlap other content.
I set up an example on JSFiddle: Draggable Example
<body>
<p>The background is transparent, but if you grab ANYWHERE in the border you can drag the image around.</p>
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/e/e1/Jupiter_(transparent).png/484px-Jupiter_(transparent).png"></img>
</body>
img{
border: solid black 1px;
}
In the example you can grab the image by holding down the left mouse button anywhere within the borders of the image, even if they are transparent. In this example my goal would be to only be able to drag the image if you grabbed a visible portion of the planet Jupiter.
Is this possible in html?
Based on your clarification in comments above, it might be easiest to draw the images in a canvas element. You can add draggability to the canvas as explained in this SO post: Make image drawn on canvas draggable with JavaScript. And you can modify that to trigger the drag flag only if a non-transparent pixel is at the clicked position.

How can I use images to change the colour of objects?

can I make an object coloriser like this? Is about car coloriser.
List of 23 thumbs images which means a colour or a mix of colours.
When you click the colour to show the image with car in the right colour.
You need to have an image of each car with each color.
For each thumb image, give it an id corresponding to its color, and one class for a listener.
Create a click listener for the class, and display the correct image based on the clicked thumb image id.
If you want a better answer you're going to have to provide some code.

Setting the outer region of Jcrop selection to invisible

In the case where an image is overlaid on top of a different image, I would like to have vision of the background image while cropping the foreground image at same time.
Example: Image A is on top of Image B. Jcrop is applied to Image A and when a selection occurs, the area of selection shows only the selected part of Image A. Image B is visible in the background, surrounding the area of selection of Image A.
Is this possible?
$(function($){
$('#target').Jcrop({
bgColor: '',
bgOpacity: 0
});
});

Swapping pixels in an icon with javascript?

I have a menu made up of icons and labels. When an icon is clicked the relevant label turns blue. I've recently heard about a technique called swapping pixels, and I wondered if it was possible to make the icon turn blue also?
Pure Javascript if possible!
This is the code that I have at the moment...
function init() {
[].forEach.call(document.querySelectorAll('.navico'), function(el) {
el.addEventListener('click', imageButtonClickHandler);
});
function imageButtonClickHandler() {
this.id.search("aboutnav");
if(this.id.match("aboutnav")) {
grey();
var a = document.getElementById("a");
a.style.color = 'blue';
a.style.fontSize = '15px';
}
the function 'grey' that gets called in the function above is JQuery and was created by my partner so I don't understand it, but it basically turns the selected menu option back to grey after it is deselected or a different icon is clicked.
Thanks in advance.
If the icon is an image, there isn't a way to use JavaScript to modify the image directly. There are, however, techniques for modifying how images look by using other images.
For example, if "turning the icon blue" meant that you wanted to change a specific pattern of colors in the icon you could create another image with just the parts you want to turn blue and everything else in the image transparent (think cut-out). Then, position the image at the same location as your icon with a higher z-index but set its visibility:hidden (or display:none, if you'd rather). Then turning the image blue would just mean showing the image.
If turning the icon blue meant that you wanted it to just have a blue "tinge" to it, you could create a semi-transparent png and use the same technique. You could also accomplish a blue tinge by just creating an element (say a div) and setting the background color to blue, then setting the transparency. In this way you could choose arbitrary colors instead of having to create an image for each color you wanted to use.

How do i display an image without its background in windows 8 html5 modern UI?

I have an image which i want to display on a html5 page.when i display the image on the page , the image's background which is white square background also appears.I only want the actual image shape to appear on the page.
I have given the link for a similar image below.In this image i just want the round shape in green color and its arrow inside it and not its square shape white background .
any idea how to display just the actual image and not the other.
http://www.bing.com/images/search?q=next+icon&view=detail&id=F55BB11D07B0F03037054A4112AE608758BDB56D&FORM=IDFRIR
The image has to be a transparent PNG for that to work. And also you have to remove it's background color on that img tag if it has
eg:
<div style="width:300px;height:300px; background-color:#000">
<img src="http://icons.iconarchive.com/icons/visualpharm/must-have/256/Next-icon.png" style="background: none;" border="0" alt="" />
</div>

Categories

Resources