开发者

Uploadify button: Style with CSS?

Is it pos开发者_高级运维sible to replace the Uploadify button (which is a graphic containing up/over/down states) with a simple CSS-styled button?


I was able to get away with something massively more simple.

xhtml:

<div id="uploadify">                  
  Upload Pictures                     
  <div id="uploadify" type="button" />
</div>                                

css:

#uploadify object { 
  position:absolute;
  left:0; right:0;  
  width:100%        
}                   

javascript:

$("#uploadify>div").uploadify({                     
  'hideButton'   : true                                
  , 'wmode'      : 'transparent'                         
  , 'uploader'   : '/static/uploadify/uploadify.swf'
  , 'script'     : '/static/uploadify.php'          
  , 'folder'     : '/_uploads'                      
  , 'multi'      : true                             
})                                                  

// If you're using jQuery UI.
$("#uploadify").button(); 

Probably a little easier, now that we have hideButton: true, not sure if @Herb knew about it.

UPDATE I wrote this answer in July of 2010. It's now March of 2013. HTML5 supports multiple file-uploads. Don't use uploadify at all; I don't.


I've been able to come up with a working solution to this. Here's the basic outline:

  • Disable the Uploadify button image buttonImg: " "
  • Make the flash object transparent wmode:"transparent"
  • Using CSS, position a fake styled button or a tag behind the flash object
  • After initializing Uploadify, set the width and height of the object to match the button behind it

The flash object will shield the button underneath it from mouseover etc. events; so to get hover effects, you'll need to take a couple of additional steps:

  • Wrap both the button and the upload object in a div
  • After initializing Uploadify, set the width and height of the wrapper div to match the button
  • You can then use jQuery to handle the .hover() events on the wrapper div and apply styles to the button

Putting it all together:

HTML

<div class="UploadifyButtonWrapper">
    <a>Upload Files</a>
    <div class="UploadifyObjectWrapper">
       <input type="file" id="Uploadify" name="Uploadify" />
    </div>
</div>

CSS

div.UploadifyButtonWrapper{
    position:relative;
}

/* fake button */
div.UploadifyButtonWrapper a {
    position:absolute; /* relative to UploadifyButtonWrapper */
    top:0;
    left:0;
    z-index:0;
    display:block;
    float:left;
    border:1px solid gray;
    padding:10px;
    background:silver;
    color:black;
}

/* pass hover effects to button */
div.UploadifyButtonWrapper a.Hover {
    background:orange;
    color:white;
}

/* position flash button above css button */
div.UploadifyObjectWrapper {
    position:relative;
    z-index:10;
}

Javascript:

$("input.Uploadify", self).uploadify({
    ...
    buttonImg: " ",
    wmode: "transparent",
    ...
});
var $buttonWrapper = $(".UploadifyButtonWrapper", self);
var $objectWrapper = $(".UploadifyObjectWrapper", self);
var $object = $("object", self);
var $fakeButton = $("a", self);
var width = $fakeButton.outerWidth();
var height = $fakeButton.outerHeight();
$object.attr("width", width).attr("height", height);
$buttonWrapper.css("width", width + "px").css("height", height + "px")
$objectWrapper.hover(function() {
    $("a", this).addClass("Hover");
}, function() {
    $("a", this).removeClass("Hover");
});


Why not just put a Wrapper around it like this:

<div class = "uploadWrapper"><input id="file_upload" name="file_upload" type="file" /></div>

Style it like this:

.uploadWrapper object {background-color: red;}
.uploadWrapper object:hover {background-color: blue;}

And use the following script:

<script type="text/javascript">
$(document).ready(function() {
  $('#file_upload').uploadify({
    'hideButton': true,
    'wmode'     : 'transparent',
    'uploader'  : '/uploadify/uploadify.swf',
    'script'    : '/uploadify/uploadify.php',
    'cancelImg' : '/uploadify/cancel.png',
    'folder'    : '/uploads',
    'auto'      : true
  });
});
</script>

Works for me ;) ... and of course you can just use background-images instead of the colors.


100% working example. Tested in Firefox, Chrome, Opera and IE6!

HTML:

<div id="uploadify-wrapper"><div id="uploadify"></div></div>
<span id="btn">Select files to upload</span>
<div id="uploadify-queue"></div>

CSS:

#uploadify-wrapper {position:absolute; overflow:hidden}

JavaScript:

$('#uploadify').uploadify({width:1000, height:1000, hideButton:true, wmode:'transparent', queueID:'uploadify-queue', ...);
$('#uploadify-wrapper').width($('#btn').outerWidth()).height($('#btn').outerHeight());


reading your answers helped me to solve this one this way

  1. First wrap the <input> into a <div class=upload-wrap>
  2. Apply styles to this new wrapper (even :hover)
  3. Use the hiddeButton option

HTML:

<div class="upload-wrap">
<input id="file_upload" type="file" name="file_upload" />
</div>

CSS:

.upload-wrap{
    background:#ff0;
    width:133px;
    height:36px;
}
.upload-wrap:hover{
    background:#f00;
}

JS

$('#file_upload').uploadify({
    'uploader'      : 'uploadify/uploadify.swf',
    'script'        : 'uploadify/uploadify.php',
    'folder'        : 'files/images',
    'hideButton'    : true,
    'wmode'     : 'transparent',
    'buttonText'    : 'Upload something'
    'width'         : 133,
    'height'        : 36    
  });

This way you're able to style your button, an keep the buttonText option available. I also had to mess a little bit with the .fla file to get the color and font for my button


A really simple way is to open the file with Flash

You can then change the background colour of the symbol UploadBtn

Save and publish the swf.


Evan was very close, but I needed to make some adjustments for it to work correctly. Here is what I ended up using:

CSS:


#uploadify { 
background: #FF5500; 
border-radius: 5px; 
}

#uploadify:hover { 
background: #B33C00; 
}

#uploadify object { 
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 25px;
}

You probably want to fine tune the height here because it does matter. Also, I aligned it from the top and left rather than left and right from the other example. I left a little styling in there as an example of how you can style the button wrapper.

HTML:

<div id="uploadify" style="position: relative;">   
  Upload Screenshots
  <div id="uploadify_button" type="button"></div>
</div>

The relative position is important for the absolute positioned button inside.

JavaScript:


$("#uploadify_button").uploadify({                     
  'hideButton' : true,                                
  'wmode'      : 'transparent',
  'uploader'   : '/static/uploadify/uploadify.swf',
  'script'     : '/static/uploadify.php',
  'folder'     : '/_uploads',         
  'multi'      : true,
  'width'      : '140',
  'height'     : '25'
});

The width and height are very important as they determine the actual clickable region within the button div. I found that without these it's only clickable in a certain area.


For Uploadify version 3.2.1, You can edit stylesheet file uploadify.css in this classes:

  • .uploadify-button
  • .uploadify:hover .uploadify-button

In my case, I comment all styles of them to remove background and border of button and default button was hide completely.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜