I created canvas inside the div tag and add background image to the canvas. Here is the code:
<div id="container" style="width: 740px; height: 420px">
<canvas id="canvas_draw"></canvas>
</div>
#container
{
position: relative;
}
#canvas_draw
{
border: 1px dashed #CCCCCC;
margin: 5px;
border-style: dotted;
border-width: 1px;
background-color: #FFFFFF;
overflow:scroll !important;
background-image:url('Images/sample.jpg');
background-repeat: no-repeat;
background-size: 900px 600px;
vertical-align: top;
}
Out put is, Scroll-bar displayed on the canvas , but unable to scroll it. I tested it on the Chrome.
Tried with applying the scroll functionality to the div, it's works fine but, unable to draw on scroll area
.So, I applied overflow: scroll
functionality to the canvas only.. How can I solve this scroll-bar issue.
Thanks in Advance...
That seems a lot of extra code to do something that seems simple using css and normal html. However, as was stated above, you'll have to size your canvas via code for each image loaded. We're doing the same thing setting the canvas to the image size via jQuery.
You need to account for the scrollbar width when you set the width of your wrapper div. You should also set this width in your code based on browser. The only issue is the scrollbar width is different between different browser rendering engines.
Here's a link talking about that: http://www.sitepoint.com/rwd-scrollbars-is-chrome-better/
Here's code that simplifies scrolling using just html and css.
Add scrollbars to canvas
Canvas is not like other html elements. Html scrollbars cannot effectively scroll through canvas content that is larger than the canvas's css size.
One fallback is to use jquery-ui to draw the scrollbars.
Here is how to add a vertical scrollbar to canvas that allows scrolling up/down over a larger image: http://jsfiddle.net/m1erickson/a9KDB/
You can add a horizontal scrollbar the same way.
Here is the code: